github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/datatools/len_test.go (about) 1 package datatools 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins/types/generic" 7 _ "github.com/lmorg/murex/builtins/types/json" 8 _ "github.com/lmorg/murex/builtins/types/jsonlines" 9 _ "github.com/lmorg/murex/builtins/types/string" 10 "github.com/lmorg/murex/lang/types" 11 "github.com/lmorg/murex/test" 12 ) 13 14 func TestLenJsonLines(t *testing.T) { 15 tests := []string{ 16 "{\"a\":1,\"b\":2}\n{\"a\":1,\"b\":2}\n{\"a\":1,\"b\":2}\n", 17 "{\"a\":1,\"b\":2}\n{\"a\":1,\"b\":2}\n{\"a\":1,\"b\":2}", 18 "{\"a\":1,\"b\":2}\r\n{\"a\":1,\"b\":2}\r\n{\"a\":1,\"b\":2}\r\n", 19 "{\"a\":1,\"b\":2}\r\n{\"a\":1,\"b\":2}\r\n{\"a\":1,\"b\":2}", 20 21 "[1,2,3,4,5]\n[1,2,3,4,5]\n[1,2,3,4,5]\n", 22 "[1,2,3,4,5]\r\n[1,2,3,4,5]\r\n[1,2,3,4,5]\r\n", 23 "[1,2,3,4,5]\n[1,2,3,4,5]\n[1,2,3,4,5]", 24 "[1,2,3,4,5]\r\n[1,2,3,4,5]\r\n[1,2,3,4,5]", 25 } 26 27 for _, s := range tests { 28 test.RunMethodTest(t, 29 cmdCount, "count", 30 s, 31 types.JsonLines, 32 []string{}, 33 `3`, 34 nil, 35 ) 36 } 37 } 38 39 func TestLenJson(t *testing.T) { 40 tests := []string{ 41 `[1,2,3,4,5]`, 42 `["1","2","3","4","5"]`, 43 `["a","b","c","d","e"]`, 44 `["abc","def","ghi","jkl","mno"]`, 45 `{"1":[], "2":[], "3":[], "4":[], "5":[]}`, 46 `{"1":[1,2], "2":[3,4], "3":[5,6], "4":[7,8], "5":[9,0]}`, 47 `{"1":{}, "2":{}, "3":{}, "4":{}, "5":{}}`, 48 `{"1":{"a":1,"b":2}, "2":{"c":3,"d":4}, "3":{"e":5,"f":6}, "4":{"g":7,"h":8}, "5":{"i":9,"j":0}}`, 49 } 50 51 for _, s := range tests { 52 test.RunMethodTest(t, 53 cmdCount, "count", 54 s, 55 types.Json, 56 []string{}, 57 `5`, 58 nil, 59 ) 60 } 61 } 62 63 func TestLenString1(t *testing.T) { 64 tests := []string{ 65 "1 2 3 4 5", 66 "a b c d e", 67 "abc def ghi jkl mno", 68 "1\t2\t3\t4\t5", 69 "a\tb\tc\td\te", 70 "abc\tdef\tghi\tjkl\tmno", 71 } 72 73 for _, s := range tests { 74 test.RunMethodTest(t, 75 cmdCount, "count", 76 s, 77 types.String, 78 []string{}, 79 `1`, 80 nil, 81 ) 82 } 83 } 84 85 func TestLenString5(t *testing.T) { 86 tests := []string{ 87 "1\n2\n3\n4\n5\n", 88 "a\nb\nc\nd\ne\n", 89 "abc\ndef\nghi\njkl\nmno\n", 90 "1\r\n2\r\n3\r\n4\r\n5\r\n", 91 "a\r\nb\r\nc\r\nd\r\ne\r\n", 92 "abc\r\ndef\r\nghi\r\njkl\r\nmno\r\n", 93 "1\n2\n3\n4\n5", 94 "a\nb\nc\nd\ne", 95 "abc\ndef\nghi\njkl\nmno", 96 "1\r\n2\r\n3\r\n4\r\n5", 97 "a\r\nb\r\nc\r\nd\r\ne", 98 "abc\r\ndef\r\nghi\r\njkl\r\nmno", 99 } 100 101 for _, s := range tests { 102 test.RunMethodTest(t, 103 cmdCount, "count", 104 s, 105 types.String, 106 []string{}, 107 `5`, 108 nil, 109 ) 110 } 111 } 112 113 func TestLenString6(t *testing.T) { 114 tests := []string{ 115 "\n1\n2\n3\n4\n5\n", 116 "\na\nb\nc\nd\ne\n", 117 "\nabc\ndef\nghi\njkl\nmno\n", 118 "\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", 119 "\r\na\r\nb\r\nc\r\nd\r\ne\r\n", 120 "\r\nabc\r\ndef\r\nghi\r\njkl\r\nmno\r\n", 121 "\r\n1\n2\n3\n4\n5", 122 "\r\na\nb\nc\nd\ne", 123 "\r\nabc\ndef\nghi\njkl\nmno", 124 "\r\n1\r\n2\r\n3\r\n4\r\n5", 125 "\r\na\r\nb\r\nc\r\nd\r\ne", 126 "\r\nabc\r\ndef\r\nghi\r\njkl\r\nmno", 127 } 128 129 for _, s := range tests { 130 test.RunMethodTest(t, 131 cmdCount, "count", 132 s, 133 types.String, 134 []string{}, 135 `6`, 136 nil, 137 ) 138 } 139 } 140 141 func TestLenGeneric1(t *testing.T) { 142 tests := []string{ 143 "1 2 3 4 5", 144 "a b c d e", 145 "abc def ghi jkl mno", 146 "1\t2\t3\t4\t5", 147 "a\tb\tc\td\te", 148 "abc\tdef\tghi\tjkl\tmno", 149 } 150 151 for _, s := range tests { 152 test.RunMethodTest(t, 153 cmdCount, "count", 154 s, 155 types.Generic, 156 []string{}, 157 `1`, 158 nil, 159 ) 160 } 161 } 162 163 func TestLenGeneric5(t *testing.T) { 164 tests := []string{ 165 "1\n2\n3\n4\n5\n", 166 "a\nb\nc\nd\ne\n", 167 "abc\ndef\nghi\njkl\nmno\n", 168 "1\r\n2\r\n3\r\n4\r\n5\r\n", 169 "a\r\nb\r\nc\r\nd\r\ne\r\n", 170 "abc\r\ndef\r\nghi\r\njkl\r\nmno\r\n", 171 "1\n2\n3\n4\n5", 172 "a\nb\nc\nd\ne", 173 "abc\ndef\nghi\njkl\nmno", 174 "1\r\n2\r\n3\r\n4\r\n5", 175 "a\r\nb\r\nc\r\nd\r\ne", 176 "abc\r\ndef\r\nghi\r\njkl\r\nmno", 177 } 178 179 for _, s := range tests { 180 test.RunMethodTest(t, 181 cmdCount, "count", 182 s, 183 types.Generic, 184 []string{}, 185 `5`, 186 nil, 187 ) 188 } 189 } 190 191 func TestLenGeneric6(t *testing.T) { 192 tests := []string{ 193 "\n1\n2\n3\n4\n5\n", 194 "\na\nb\nc\nd\ne\n", 195 "\nabc\ndef\nghi\njkl\nmno\n", 196 "\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", 197 "\r\na\r\nb\r\nc\r\nd\r\ne\r\n", 198 "\r\nabc\r\ndef\r\nghi\r\njkl\r\nmno\r\n", 199 "\r\n1\n2\n3\n4\n5", 200 "\r\na\nb\nc\nd\ne", 201 "\r\nabc\ndef\nghi\njkl\nmno", 202 "\r\n1\r\n2\r\n3\r\n4\r\n5", 203 "\r\na\r\nb\r\nc\r\nd\r\ne", 204 "\r\nabc\r\ndef\r\nghi\r\njkl\r\nmno", 205 } 206 207 for _, s := range tests { 208 test.RunMethodTest(t, 209 cmdCount, "count", 210 s, 211 types.Generic, 212 []string{}, 213 `6`, 214 nil, 215 ) 216 } 217 }