|
| 1 | +[ |
| 2 | + { |
| 3 | + "description": "string methods macro syntax", |
| 4 | + "tests": [ |
| 5 | + { |
| 6 | + "description": "method concat", |
| 7 | + "script": { "$$str.concat": [ "a", "b", "c" ] }, |
| 8 | + "result": "abc" |
| 9 | + }, |
| 10 | + { |
| 11 | + "description": "method slice", |
| 12 | + "script": { "$$str.slice": [ "foobar", 1, 4 ] }, |
| 13 | + "result": "oob" |
| 14 | + }, |
| 15 | + { |
| 16 | + "description": "method slice - only start specified", |
| 17 | + "script": { "$$str.slice": [ "foobar", 3 ] }, |
| 18 | + "result": "bar" |
| 19 | + }, |
| 20 | + { |
| 21 | + "description": "method slice - relative end", |
| 22 | + "script": { "$$str.slice": [ "foobar", 0, -1 ] }, |
| 23 | + "result": "fooba" |
| 24 | + }, |
| 25 | + { |
| 26 | + "description": "method pos", |
| 27 | + "script": { "$$str.pos": [ "foobar", "bar" ] }, |
| 28 | + "result": 3 |
| 29 | + }, |
| 30 | + { |
| 31 | + "description": "method pos, str not found", |
| 32 | + "script": { "$$str.pos": [ "foobar", "abc" ] }, |
| 33 | + "result": -1 |
| 34 | + }, |
| 35 | + { |
| 36 | + "description": "method lower", |
| 37 | + "script": { "$$str.lower": "FooBar" }, |
| 38 | + "result": "foobar" |
| 39 | + }, |
| 40 | + { |
| 41 | + "description": "method upper", |
| 42 | + "script": { "$$str.upper": "FooBar" }, |
| 43 | + "result": "FOOBAR" |
| 44 | + } |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "description": "string methods full syntax", |
| 49 | + "tests": [ |
| 50 | + { |
| 51 | + "description": "method concat", |
| 52 | + "script": { |
| 53 | + "$exec": "str", |
| 54 | + "$method": "concat", |
| 55 | + "$args": [ "a", "b", "c" ] |
| 56 | + }, |
| 57 | + "result": "abc" |
| 58 | + }, |
| 59 | + { |
| 60 | + "description": "method slice", |
| 61 | + "script": { |
| 62 | + "$exec": "str", |
| 63 | + "$method": "slice", |
| 64 | + "$args": [ "foobar", 1, 4 ] |
| 65 | + }, |
| 66 | + "result": "oob" |
| 67 | + }, |
| 68 | + { |
| 69 | + "description": "method slice - only start specified", |
| 70 | + "script": { |
| 71 | + "$exec": "str", |
| 72 | + "$method": "slice", |
| 73 | + "$args": [ "foobar", 3 ] |
| 74 | + }, |
| 75 | + "result": "bar" |
| 76 | + }, |
| 77 | + { |
| 78 | + "description": "method slice - relative end", |
| 79 | + "script": { |
| 80 | + "$exec": "str", |
| 81 | + "$method": "slice", |
| 82 | + "$args": [ "foobar", 0, -1 ] |
| 83 | + }, |
| 84 | + "result": "fooba" |
| 85 | + }, |
| 86 | + { |
| 87 | + "description": "method pos", |
| 88 | + "script": { |
| 89 | + "$exec": "str", |
| 90 | + "$method": "pos", |
| 91 | + "$args": [ "foobar", "bar" ] |
| 92 | + }, |
| 93 | + "result": 3 |
| 94 | + }, |
| 95 | + { |
| 96 | + "description": "method pos, str not found", |
| 97 | + "script": { |
| 98 | + "$exec": "str", |
| 99 | + "$method": "pos", |
| 100 | + "$args": [ "foobar", "abc" ] |
| 101 | + }, |
| 102 | + "result": -1 |
| 103 | + }, |
| 104 | + { |
| 105 | + "description": "method lower", |
| 106 | + "script": { |
| 107 | + "$exec": "str", |
| 108 | + "$method": "lower", |
| 109 | + "$args": "FooBar" |
| 110 | + }, |
| 111 | + "result": "foobar" |
| 112 | + }, |
| 113 | + { |
| 114 | + "description": "method upper", |
| 115 | + "script": { |
| 116 | + "$exec": "str", |
| 117 | + "$method": "upper", |
| 118 | + "$args": "FooBar" |
| 119 | + }, |
| 120 | + "result": "FOOBAR" |
| 121 | + } |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "description": "string methods errors", |
| 126 | + "tests": [ |
| 127 | + { |
| 128 | + "description": "method concat - arguments should be strings", |
| 129 | + "script": { "$$str.concat": [ 1, 2, 3 ] }, |
| 130 | + "error": true |
| 131 | + }, |
| 132 | + { |
| 133 | + "description": "method slice - first argument should be string", |
| 134 | + "script": { "$$str.slice": [ 123, 1, 2 ] }, |
| 135 | + "error": true |
| 136 | + }, |
| 137 | + { |
| 138 | + "description": "method slice - indices should be numbers", |
| 139 | + "script": { "$$str.slice": [ "foobar", "3" ] }, |
| 140 | + "error": true |
| 141 | + }, |
| 142 | + { |
| 143 | + "description": "method pos - arguments should be strings", |
| 144 | + "script": { "$$str.pos": [ 1234, 23 ] }, |
| 145 | + "error": true |
| 146 | + }, |
| 147 | + { |
| 148 | + "description": "method lower - argument should be string", |
| 149 | + "script": { "$$str.lower": 1234 }, |
| 150 | + "error": true |
| 151 | + }, |
| 152 | + { |
| 153 | + "description": "method upper - argument should be string", |
| 154 | + "script": { "$$str.upper": 1234 }, |
| 155 | + "error": true |
| 156 | + } |
| 157 | + ] |
| 158 | + } |
| 159 | +] |
0 commit comments