diff --git a/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal index 6fdd4fe..cedf454 100644 --- a/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal @@ -23,431 +23,421 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; CustomRecord27Array|csv:Error vcr27a = csv:transform([value, value, value], {}, CustomRecord27Array); - test:assertEquals(vcr27a , [ - {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, - {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, - {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()} - ]); + test:assertEquals(vcr27a, [ + {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, + {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, + {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()} + ]); AnydataMapArray|csv:Error vanydma = csv:transform([value, value, value], {}, AnydataMapArray); - test:assertEquals(vanydma , [ - value, - value, - value - ]); + test:assertEquals(vanydma, [ + value, + value, + value + ]); JsonMapArray|csv:Error vjma = csv:transform([value, value, value], {}, JsonMapArray); - test:assertEquals(vjma , [ - value, - value, - value - ]); - - record{|int...;|}[]|csv:Error irrma = csv:transform([{"a": 1}, {"a": i1, "b": i2}, {"a": i1, "b": i2, "c": s1}]); - test:assertEquals(irrma , [ - {a:1}, - {a: i1, b: i2}, - {a: i1, b: i2} - ]); - - record{|decimal...;|}[]|csv:Error drra = csv:transform([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); - test:assertTrue(drra is record{|decimal...;|}[]); - test:assertEquals(drra , [ - {a: d1}, - {a: d2, b: d3}, - {a: d4, b: -3.21d, d: f3} - ]); - - record{|string...;|}[]|csv:Error srra = csv:transform([{"a": "string"}, {"c": 1, "a": s1, "b": s2}, {"a": b1, "b": s3, "c": d1}]); - test:assertEquals(srra , [ - {a: "string"}, - {a: s1, b: s2}, - {b: s3} - ]); - - record{|float...;|}[]|csv:Error frra = csv:transform([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); - test:assertEquals(frra , [ - {a: 1.2, b: 1.2}, - {a: d2, b: d3}, - {a: d4, b: f2} - ]); - - record{|float a; decimal b;|}[]|csv:Error fdc1a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); - test:assertEquals(fdc1a , [ - {a: d1, b: d2}, - {a: f1, b: f2}, - {a: d2, b: f2}, - {a: f2, b: d2} - ]); - - record{|float a; decimal ...;|}[]|csv:Error fdc2a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); - test:assertEquals(fdc2a , [ - {a: d1, b: d2}, - {a: f1, b: f2}, - {a: d2, b: f2}, - {a: f2, b: d2} - ]); - - record{|decimal b; float...;|}[]|csv:Error fdc3a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); - test:assertEquals(fdc3a , [ - {a: d1, b: d2}, - {a: f1, b: f2}, - {a: d2, b: f2}, - {a: f2, b: d2} - ]); + test:assertEquals(vjma, [ + value, + value, + value + ]); + + record {|int...;|}[]|csv:Error irrma = csv:transform([{"a": 1}, {"a": i1, "b": i2}, {"a": i1, "b": i2, "c": s1}]); + test:assertEquals(irrma, [ + {a: 1}, + {a: i1, b: i2}, + {a: i1, b: i2} + ]); + + record {|decimal...;|}[]|csv:Error drra = csv:transform([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); + test:assertTrue(drra is record {|decimal...;|}[]); + test:assertEquals(drra, [ + {a: d1}, + {a: d2, b: d3}, + {a: d4, b: -3.21d, d: f3} + ]); + + record {|string...;|}[]|csv:Error srra = csv:transform([{"a": "string"}, {"c": 1, "a": s1, "b": s2}, {"a": b1, "b": s3, "c": d1}]); + test:assertEquals(srra, [ + {a: "string"}, + {a: s1, b: s2}, + {b: s3} + ]); + + record {|float...;|}[]|csv:Error frra = csv:transform([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); + test:assertEquals(frra, [ + {a: 1.2, b: 1.2}, + {a: d2, b: d3}, + {a: d4, b: f2} + ]); + + record {|float a; decimal b;|}[]|csv:Error fdc1a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + test:assertEquals(fdc1a, [ + {a: d1, b: d2}, + {a: f1, b: f2}, + {a: d2, b: f2}, + {a: f2, b: d2} + ]); + + record {|float a; decimal...;|}[]|csv:Error fdc2a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + test:assertEquals(fdc2a, [ + {a: d1, b: d2}, + {a: f1, b: f2}, + {a: d2, b: f2}, + {a: f2, b: d2} + ]); + + record {|decimal b; float...;|}[]|csv:Error fdc3a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + test:assertEquals(fdc3a, [ + {a: d1, b: d2}, + {a: f1, b: f2}, + {a: d2, b: f2}, + {a: f2, b: d2} + ]); } type A decimal|int; + type A2 int|decimal; -type B readonly & A | C; -type B2 readonly & C | readonly & A2; + +type B readonly & A|C; + +type B2 readonly & C|readonly & A2; + type C string|boolean; + type C2 boolean|string; @test:Config function testFromCsvWithIntersectionTypeCompatibility2() { - record{ - readonly & int a; - readonly & string b; - (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error r1a = csv:parseString( string `a,b,c + record { + readonly & int a; + readonly & string b; + (readonly & boolean)|(readonly & decimal) c; + }[]|csv:Error r1a = csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r1a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); + test:assertEquals(r1a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); - record{A a; B b; C c;}[]|csv:Error r2a = csv:parseString( string `a,b,c + record {A a; B b; C c;}[]|csv:Error r2a = csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r2a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); + test:assertEquals(r2a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); - record{A2 a; B2 b; C2 c;}[]|csv:Error r3a = csv:parseString( string `a,b,c + record {A2 a; B2 b; C2 c;}[]|csv:Error r3a = csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r3a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); + test:assertEquals(r3a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); - record{|A2 a; B2 b; C2...;|}[]|csv:Error r4a = csv:parseString( string ` + record {|A2 a; B2 b; C2...;|}[]|csv:Error r4a = csv:parseString(string ` a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`, {header: 1}); - test:assertEquals(r4a , [ - {a: 1, b: "string", c: true, d: "string"}, - {a: 2, b: "string2", c: false, d: "string2"}, - {a: 3, b: "string3", c: true, d: "string3"} - ]); + test:assertEquals(r4a, [ + {a: 1, b: "string", c: true, d: "string"}, + {a: 2, b: "string2", c: false, d: "string2"}, + {a: 3, b: "string3", c: true, d: "string3"} + ]); - record{|C2...;|}[]|csv:Error r5a = csv:parseString( string `a,b,c,d + record {|C2...;|}[]|csv:Error r5a = csv:parseString(string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r5a , [ - {a: "1", b: "string", c: true, d: "string"}, - {a: "2", b: "string2", c: false, d: "string2"}, - {a: "3", b: "string3", c: true, d: "string3"} - ]); + test:assertEquals(r5a, [ + {a: "1", b: "string", c: true, d: "string"}, + {a: "2", b: "string2", c: false, d: "string2"}, + {a: "3", b: "string3", c: true, d: "string3"} + ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error r16a = - csv:parseString( string `a,b,c + [readonly & int, readonly & string, (readonly & boolean)|(readonly & decimal)][]|csv:Error r16a = + csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r16a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(r16a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A, B, C][]|csv:Error r17a = csv:parseString( - string `a,b,c + string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r17a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(r17a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A2, B2, C2][]|csv:Error r18a = csv:parseString( - string `a,b,c + string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r18a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(r18a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A2, B2, C2...][]|csv:Error r19a = csv:parseString( - string `a,b,c,d + string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r19a , [ - [1, "string", true, "string"], - [2, "string2", false, "string2"], - [3, "string3", true, "string3"] - ]); + test:assertEquals(r19a, [ + [1, "string", true, "string"], + [2, "string2", false, "string2"], + [3, "string3", true, "string3"] + ]); [C2...][]|csv:Error r20a = csv:parseString( - string `a,b,c,d + string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r20a, [["1", "string",true, "string"], - ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); - - - record{A a; B b; C c;}[]|csv:Error rt2a = csv:transform( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); - - test:assertEquals(rt2a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{ - readonly & int a; - readonly & string b; - (readonly & boolean) | (readonly & decimal) c; + test:assertEquals(r20a, [ + ["1", "string", true, "string"], + ["2", "string2", false, "string2"], + ["3", "string3", true, "string3"] + ]); + + record {A a; B b; C c;}[]|csv:Error rt2a = csv:transform( + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); + + test:assertEquals(rt2a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record { + readonly & int a; + readonly & string b; + (readonly & boolean)|(readonly & decimal) c; }[]|csv:Error rt1a = csv:transform( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); - - test:assertEquals(rt1a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A2 a; B2 b; C2 c;}[]|csv:Error rt3a = csv:transform( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); - - test:assertEquals(rt3a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt4a = csv:transform( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}]); - - test:assertEquals(rt4a , [ - {a: 1, b: "string", c: true, d: "string"}, - {a: 2, b: "string2", c: false, d: "string2"}, - {a: 3, b: "string3", c: true, d: "string3"} - ]); - - record{|C2...;|}[]|csv:Error rt5a = csv:transform( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}]); - - test:assertEquals(rt5a , [ - {b: "string", c: true, d: "string"}, - {b: "string2", c: false, d: "string2"}, - {b: "string3", c: true, d: "string3"} - ]); - - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt6a = + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); + + test:assertEquals(rt1a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {A2 a; B2 b; C2 c;}[]|csv:Error rt3a = csv:transform( + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); + + test:assertEquals(rt3a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {|A2 a; B2 b; C2...;|}[]|csv:Error rt4a = csv:transform( + [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}]); + + test:assertEquals(rt4a, [ + {a: 1, b: "string", c: true, d: "string"}, + {a: 2, b: "string2", c: false, d: "string2"}, + {a: 3, b: "string3", c: true, d: "string3"} + ]); + + record {|C2...;|}[]|csv:Error rt5a = csv:transform( + [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}]); + + test:assertEquals(rt5a, [ + {b: "string", c: true, d: "string"}, + {b: "string2", c: false, d: "string2"}, + {b: "string3", c: true, d: "string3"} + ]); + + [readonly & int, readonly & string, (readonly & boolean)|(readonly & decimal)][]|csv:Error rt6a = csv:transform( - [{"a": 1, "b": "string", "c": true}, - {"a": 2, "b": "string2", "c": false}, - {"a": 3, "b": "string3", "c": true} - ], {headersOrder: ["a", "b", "c"]}); - - test:assertEquals(rt6a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + [ + {"a": 1, "b": "string", "c": true}, + {"a": 2, "b": "string2", "c": false}, + {"a": 3, "b": "string3", "c": true} + ], {headersOrder: ["a", "b", "c"]}); + + test:assertEquals(rt6a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A, B, C][]|csv:Error rt7a = csv:transform( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , {headersOrder: ["a", "b", "c"]}); + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] + , {headersOrder: ["a", "b", "c"]}); - test:assertEquals(rt7a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(rt7a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A2, B2, C2][]|csv:Error rt8a = csv:transform( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , {headersOrder: ["a", "b", "c"]}); + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] + , {headersOrder: ["a", "b", "c"]}); - test:assertEquals(rt8a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(rt8a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A2, B2, C2...][]|csv:Error rt9a = csv:transform( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , {headersOrder: ["a", "b", "c", "d"]}); + [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] + , {headersOrder: ["a", "b", "c", "d"]}); - test:assertEquals(rt9a , [ - [1, "string", true, "string"], - [2, "string2", false, "string2"], - [3, "string3", true, "string3"] - ]); + test:assertEquals(rt9a, [ + [1, "string", true, "string"], + [2, "string2", false, "string2"], + [3, "string3", true, "string3"] + ]); [C2...][]|csv:Error rt10a = csv:transform( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , {headersOrder: ["a", "b", "c", "d"]}); + [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] + , {headersOrder: ["a", "b", "c", "d"]}); test:assertTrue(rt10a is csv:Error); test:assertEquals((rt10a).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:C2")); - record{ - readonly & int a; - readonly & string b; - (readonly & boolean) | (readonly & decimal) c; + record { + readonly & int a; + readonly & string b; + (readonly & boolean)|(readonly & decimal) c; }[]|csv:Error rt11a = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); - - test:assertEquals(rt11a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A a; B b; C c;}[]|csv:Error rt12a = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); - - test:assertEquals(rt12a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"], stringConversion: false}); - - test:assertTrue(rt12a_2 is csv:Error); - test:assertEquals((rt12a_2).message(), - common:generateErrorMessageForInvalidFieldType("1", "a")); - - record{string|decimal a; B b; C c;}[]|csv:Error rt12a_3 = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); - - test:assertEquals(rt12a_3 , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); - - test:assertEquals(rt13a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseList( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , {customHeaders: ["a", "b", "c", "d"]}); - - test:assertEquals(rt14a , [ - {a: 1, b: "string", c: true, d: "string"}, - {a: 2, b: "string2", c: false, d: "string2"}, - {a: 3, b: "string3", c: true, d: "string3"} - ]); - - record{|C2...;|}[]|csv:Error rt15a = csv:parseList( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , {customHeaders: ["a", "b", "c", "d"]}); - - test:assertEquals(rt15a , [ - {a: "1", b: "string", c: true, d: "string"}, - {a: "2", b: "string2", c: false, d: "string2"}, - {a: "3", b: "string3", c: true, d: "string3"} - ]); - - record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseList( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]], - {stringConversion: false, customHeaders: ["a", "b", "c", "d"]}); - - test:assertEquals(rt15a_2 , [ - {a: "1", b: "string", c: "true", d: "string"}, - {a: "2", b: "string2", c: "false", d: "string2"}, - {a: "3",b: "string3", c: "true", d: "string3"} - ]); - - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt16a = + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt11a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {A a; B b; C c;}[]|csv:Error rt12a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt12a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {string|decimal a; B b; C c;}[]|csv:Error rt12a_3 = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt12a_3, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt13a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseList( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] + , {customHeaders: ["a", "b", "c", "d"]}); + + test:assertEquals(rt14a, [ + {a: 1, b: "string", c: true, d: "string"}, + {a: 2, b: "string2", c: false, d: "string2"}, + {a: 3, b: "string3", c: true, d: "string3"} + ]); + + record {|C2...;|}[]|csv:Error rt15a = csv:parseList( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] + , {customHeaders: ["a", "b", "c", "d"]}); + + test:assertEquals(rt15a, [ + {a: "1", b: "string", c: true, d: "string"}, + {a: "2", b: "string2", c: false, d: "string2"}, + {a: "3", b: "string3", c: true, d: "string3"} + ]); + + [readonly & int, readonly & string, (readonly & boolean)|(readonly & decimal)][]|csv:Error rt16a = csv:parseList( - [["1", "string", "true"], - ["2", "string2", "false"], - ["3", "string3", "true"]]); - - test:assertEquals(rt16a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + [ + ["1", "string", "true"], + ["2", "string2", "false"], + ["3", "string3", "true"] + ]); + + test:assertEquals(rt16a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A, B, C][]|csv:Error rt17a = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); - test:assertEquals(rt17a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A, B, C][]|csv:Error rt17a_2 = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {stringConversion: false}); - - test:assertTrue(rt17a_2 is csv:Error); - test:assertEquals((rt17a_2).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:A")); + test:assertEquals(rt17a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A2, B2, C2][]|csv:Error rt18a = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); - test:assertEquals(rt18a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(rt18a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); [A2, B2, C2...][]|csv:Error rt19a = csv:parseList( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); - test:assertEquals(rt19a , [ - [1, "string", true, "string"], - [2, "string2", false, "string2"], - [3, "string3", true, "string3"] - ]); + test:assertEquals(rt19a, [ + [1, "string", true, "string"], + [2, "string2", false, "string2"], + [3, "string3", true, "string3"] + ]); [C2...][]|csv:Error rt20a = csv:parseList( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); - test:assertEquals(rt20a, [["1", "string",true, "string"], - ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); -} \ No newline at end of file + test:assertEquals(rt20a, [ + ["1", "string", true, "string"], + ["2", "string2", false, "string2"], + ["3", "string3", true, "string3"] + ]); +} diff --git a/ballerina-tests/union-type-tests/tests/test_with_union_types.bal b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal index 0d216d2..f7dda6b 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_union_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal @@ -311,7 +311,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: true}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -320,15 +320,6 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); - test:assertEquals(csv1op9_2, [ - {}, - {}, - {}, - {}, - {} - ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, @@ -345,10 +336,6 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); - test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| int a; string...; |})[]'"); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, @@ -516,10 +503,6 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ["5"] ]); - ([boolean...]|[int...])[]|csv:Error csv1op8 = csv:parseList(value, {stringConversion: false}); - test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...]|[int...])[]'"); - ([string...]|[int...])[]|csv:Error csv1op8_2 = csv:parseList(value, {}); test:assertEquals(csv1op8_2, value); @@ -826,7 +809,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: true}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -835,15 +818,6 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); - test:assertEquals(csv1op9_2, [ - {}, - {}, - {}, - {}, - {} - ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, @@ -860,10 +834,6 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); - test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| int a; int...; |}[]|union_type_tests:record {| int a; string...; |}[])'"); - record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, @@ -1025,10 +995,6 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ["5"] ]); - [boolean...][]|[int...][]|csv:Error csv1op8 = csv:parseList(value, {stringConversion: false}); - test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...][]|[int...][])'"); - [string...][]|[int...][]|csv:Error csv1op8_2 = csv:parseList(value, {}); test:assertEquals(csv1op8_2, value); diff --git a/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal index 895a90a..10a83a9 100644 --- a/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal @@ -20,7 +20,7 @@ import ballerina/test; @test:Config function testCSVEncoding() returns error? { - record {}[]|csv:Error rec; + record {}[]|csv:Error rec; string csvStr = string `value Alice @@ -34,63 +34,63 @@ function testCSVEncoding() returns error? { @test:Config function testCSVLocale() { - record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; + record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; - rec = csv:parseString(string ` + rec = csv:parseString(string ` name, completed tasks, city Alice, "1234", New York Bob, "1,234", London €123, "12,34", Berlin`, {header: 1, locale: "fr_FR"}); - test:assertEquals(rec, [ - {name: "Alice", "completed tasks": 1234, city: "New York"}, - {name: "Bob", "completed tasks": 1.234, city: "London"}, - {name: "€123", "completed tasks": 12.34, city: "Berlin"} - ]); + test:assertEquals(rec, [ + {name: "Alice", "completed tasks": 1234, city: "New York"}, + {name: "Bob", "completed tasks": 1.234, city: "London"}, + {name: "€123", "completed tasks": 12.34, city: "Berlin"} + ]); - rec = csv:parseString(string ` + rec = csv:parseString(string ` name, completed tasks, city Alice, "1234", New York Bob, "1.234", London €123, "12.34", Berlin`, {header: 1, locale: "en"}); test:assertEquals(rec, [ - {name: "Alice", "completed tasks": 1234, city: "New York"}, - {name: "Bob", "completed tasks": 1.234, city: "London"}, - {name: "€123", "completed tasks": 12.34, city: "Berlin"} - ]); + {name: "Alice", "completed tasks": 1234, city: "New York"}, + {name: "Bob", "completed tasks": 1.234, city: "London"}, + {name: "€123", "completed tasks": 12.34, city: "Berlin"} + ]); - rec = csv:parseString(string ` + rec = csv:parseString(string ` name, completed tasks, city Alice, "1234", New York Bob, "1.234", London €123, "12.34", Berlin`, {header: 1, locale: "en_US_WIN"}); - test:assertEquals(rec, [ - {name: "Alice", "completed tasks": 1234, city: "New York"}, - {name: "Bob", "completed tasks": 1.234, city: "London"}, - {name: "€123", "completed tasks": 12.34, city: "Berlin"} - ]); + test:assertEquals(rec, [ + {name: "Alice", "completed tasks": 1234, city: "New York"}, + {name: "Bob", "completed tasks": 1.234, city: "London"}, + {name: "€123", "completed tasks": 12.34, city: "Berlin"} + ]); } @test:Config {dependsOn: [testCSVLocale]} function testFromCsvStringWithParserOptions() { [int, string, boolean, decimal, float, string][]|csv:Error csv1op3 = csv:parseString(csvStringData1, option3); test:assertEquals(csv1op3, [ - [3, "string3", false, 1.23, 1.23, "()"], - [4, "string4", true, -6.51, -6.51, "()"], - [5, "string5", true, 3, 3.0, "()"] - ]); + [3, "string3", false, 1.23, 1.23, "()"], + [4, "string4", true, -6.51, -6.51, "()"], + [5, "string5", true, 3, 3.0, "()"] + ]); record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_2 = csv:parseString(csvStringData1, ptOption1); test:assertEquals(csv1op3_2, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: "()"} + ]); record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_3 = csv:parseString(csvStringData1, ptOption2); test:assertEquals(csv1op3_3, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: "()"} + ]); [int, string, boolean, decimal, float, string][]|csv:Error csv2op4 = csv:parseString(csvStringData2, option4); test:assertEquals(csv2op4, []); @@ -100,35 +100,35 @@ function testFromCsvStringWithParserOptions() { record {}[]|csv:Error csv2op4_3 = csv:parseString(csvStringData2, ptOption4); test:assertEquals(csv2op4_3, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} + ]); [int, string, boolean, decimal, float, string][]|csv:Error csv3op3 = csv:parseString(csvStringData3, option3); test:assertEquals(csv3op3, [ - [3, "string3", false, 1.23, 1.23, "()"], - [4, "string4", true, -6.51, -6.51, "()"], - [5, "string5", true, 3, 3.0, "()"] - ]); + [3, "string3", false, 1.23, 1.23, "()"], + [4, "string4", true, -6.51, -6.51, "()"], + [5, "string5", true, 3, 3.0, "()"] + ]); record {}[]|csv:Error csv3op3_2 = csv:parseString(csvStringData3, ptOption1); test:assertEquals(csv3op3_2, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} + ]); record {}[]|csv:Error csv3op3_3 = csv:parseString(csvStringData3, ptOption2); test:assertEquals(csv3op3_3, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} + ]); record {}[]|csv:Error csv3op3_4 = csv:parseString(csvStringData3, {header: 9, skipLines: "2-10"}); test:assertEquals(csv3op3_4, [ - {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} - ]); + {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} + ]); } @test:Config {dependsOn: [testCSVLocale]} @@ -139,73 +139,73 @@ function testFromCsvStringWithHeaderLessParserOptions() { record {}[]|csv:Error csv1op5_2 = csv:parseString(csvStringData1, ptOption5); test:assertEquals(csv1op5_2, [ - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); record {}[]|csv:Error csv1op6_2 = csv:parseString(csvStringData1, {header: false, skipLines: [3, 5]}); test:assertEquals(csv1op6_2, [ - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); record {}[]|csv:Error csv3op6_2 = csv:parseString(csvStringData3, {header: false, skipLines: [1, 3, 5, -1, 100, 100]}); test:assertEquals(csv3op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); record {}[]|csv:Error csv4op6_2 = csv:parseString(csvStringData4, {header: false, skipLines: [2, 4, -1, 100, 100]}); test:assertEquals(csv4op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); record {}[]|csv:Error csv5op6_2 = csv:parseString(csvStringData5, {header: false, skipLines: [2, 4, -1, 100, 100]}); test:assertEquals(csv5op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); record {}[]|csv:Error csv6op6_2 = csv:parseString(csvStringData6, {header: false, skipLines: [2, 4, -1, 100, 100]}); test:assertEquals(csv6op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); record {}[]|csv:Error csv2op6_2 = csv:parseString(csvStringData2, {header: false, skipLines: [5, 7]}); test:assertEquals(csv2op6_2, [ - {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, - {'1: "// comment"}, - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, + {'1: "// comment"}, + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); } @test:Config {dependsOn: [testCSVLocale]} function testHeaderOption() { record {}[]|csv:Error csv2cop1 = csv:parseString(csvStringData2, {header: 4}); test:assertEquals(csv2cop1, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, - {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); record {}[]|csv:Error csv2cop2 = csv:parseString(csvStringData2, {header: 100}); test:assertTrue(csv2cop2 is csv:Error); - test:assertEquals(( csv2cop2).message(), "The provided header row is empty"); + test:assertEquals((csv2cop2).message(), "The provided header row is empty"); record {}[]|csv:Error csv2cop3 = csv:parseString(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); @@ -433,116 +433,116 @@ function testCommentConfigOption2() { function testSkipLineParserOption() { [int, string, boolean, decimal, float, ()][]|csv:Error csv1cp = csv:parseString(csvStringData1, {skipLines: [], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [0], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [0, 4, 10], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: "1-5", header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [4, 2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: "2-4", header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [4, 2, -1], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [4, -1, 2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [10], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [-2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: [-2, 0, 2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: "0-2", header: 1}); test:assertEquals(csv1cp, [ - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); } @test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}); test:assertEquals(bm1ba, [ - [true, false], - [true, false] - ]); + [true, false], + [true, false] + ]); anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}); test:assertEquals(bm1ba2, [ - [false, true], - [false, true] - ]); + [false, true], + [false, true] + ]); anydata[][]|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["b1", "n1", "b2", "n2", "b3"]}); test:assertTrue(bm2ba is csv:Error); @@ -589,67 +589,66 @@ function testCustomHeaderOption() { test:assertTrue(ct1br6 is csv:Error); test:assertEquals((ct1br6).message(), common:generateErrorMessageForMissingRequiredField("c")); - record {string a; string b;}[]|csv:Error ct1br7 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], - stringConversion: false - }); + record {string a; string b;}[]|csv:Error ct1br7 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + customHeaders: ["a", "e", "b"] + }); test:assertEquals(ct1br7, [ - {a: "a", e: "1", b: "true"}, - {a: "a", e: "1", b: "true"} - ]); + {a: "a", e: 1, b: "true"}, + {a: "a", e: 1, b: "true"} + ]); - record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], - stringConversion: false - }); + record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + customHeaders: ["a", "e", "b"] + }); test:assertEquals(ct1br8, [ - {a: "a", b: "true"}, - {a: "a", b: "true"} - ]); + {a: "a", b: "true"}, + {a: "a", b: "true"} + ]); - record {|string...;|}[]|csv:Error ct1br9 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], - stringConversion: false - }); + record {|string...;|}[]|csv:Error ct1br9 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + customHeaders: ["a", "e", "b"] + }); test:assertEquals(ct1br9, [ - {a: "a", b: "true", e: "1"}, - {a: "a", b: "true", e: "1"} - ]); + {a: "a", b: "true", e: "1"}, + {a: "a", b: "true", e: "1"} + ]); record {|string...;|}[]|csv:Error ct1br10 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { - stringConversion: false - }); + }); test:assertEquals(ct1br10, [ - {'1: "a", '3: "true", '2: "1"}, - {'1: "a", '3: "true", '2: "1"} - ]); + {'1: "a", '3: "true", '2: "1"}, + {'1: "a", '3: "true", '2: "1"} + ]); } @test:Config function testCustomHeaderParserOption2() { record {}[]|csv:Error ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["a", "b"]}); test:assertEquals(ct1br, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, - {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, - {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["b", "a"]}); test:assertEquals(ct1br, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, - {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: []}); test:assertTrue(ct1br2 is csv:Error); @@ -661,57 +660,57 @@ function testCustomHeaderParserOption2() { record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(ct1br4, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, - {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseString(csvStringData4, {header: 1, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertTrue(ct1br5 is csv:Error); ct1br5 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5, [ - {f: 1, e: "string1", d: true, c: 2.234, b: 2.234, a: ()}, - {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, - {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, - {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, - {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} - ]); + {f: 1, e: "string1", d: true, c: 2.234, b: 2.234, a: ()}, + {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, + {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, + {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, + {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} + ]); record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_2, [ - {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, - {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, - {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, - {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} - ]); + {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, + {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, + {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, + {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} + ]); record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_3 = csv:parseString(csvStringData4, {skipLines: [1], header: false, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_3, [ - {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, - {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, - {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, - {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} - ]); + {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, + {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, + {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, + {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} + ]); record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ - {e1: "string1", d1: true}, - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); + {e1: "string1", d1: true}, + {e1: "string2", d1: false}, + {e1: "string3", d1: false}, + {e1: "string4", d1: true}, + {e1: "string5", d1: true} + ]); record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); + {e1: "string2", d1: false}, + {e1: "string3", d1: false}, + {e1: "string4", d1: true}, + {e1: "string5", d1: true} + ]); record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["e1", "d1"]}); test:assertTrue(ct1br8 is csv:Error); @@ -719,12 +718,12 @@ function testCustomHeaderParserOption2() { record {|boolean d1; string e1;|}[]|csv:Error ct1br9 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ - {e1: "string1", d1: true}, - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); + {e1: "string1", d1: true}, + {e1: "string2", d1: false}, + {e1: "string3", d1: false}, + {e1: "string4", d1: true}, + {e1: "string5", d1: true} + ]); record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); @@ -732,12 +731,12 @@ function testCustomHeaderParserOption2() { record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ - {e1: "string1", d1: "true"}, - {e1: "string2", d1: "false"}, - {e1: "string3", d1: "false"}, - {e1: "string4", d1: "true"}, - {e1: "string5", d1: "true"} - ]); + {e1: "string1", d1: "true"}, + {e1: "string2", d1: "false"}, + {e1: "string3", d1: "false"}, + {e1: "string4", d1: "true"}, + {e1: "string5", d1: "true"} + ]); record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); test:assertTrue(ct1br13 is csv:Error); @@ -896,21 +895,21 @@ function testEscapeCharactersWithParserOptions() { function testDelimiterWithParserOptions() { record {}[]|csv:Error cn = csv:parseString(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn, [ - {a: 1, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 2, b: "s,tring", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 3, b: "stri,ng", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 4, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} - ]); + {a: 1, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 2, b: "s,tring", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 3, b: "stri,ng", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 4, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} + ]); anydata[][]|csv:Error cn2 = csv:parseString(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn2, [ - [1, "string", true, 2.234, -3.21, ()], - [2, "s,tring", true, 2.234, -3.21, ()], - [3, "stri,ng", true, 2.234, -3.21, ()], - [4, "string", true, 2.234, -3.21, ()], - [5, "string", true, 2.234, -3.21, ()] - ]); + [1, "string", true, 2.234, -3.21, ()], + [2, "s,tring", true, 2.234, -3.21, ()], + [3, "stri,ng", true, 2.234, -3.21, ()], + [4, "string", true, 2.234, -3.21, ()], + [5, "string", true, 2.234, -3.21, ()] + ]); } @test:Config @@ -950,7 +949,7 @@ function testSkipLineParameterWithOutputHeaderConfig() { 3,4 4,5`; - record{}[]|csv:Error result = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); + record {}[]|csv:Error result = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); test:assertEquals(result, [{a: 1, b: 2}, {a: 4, b: 5}]); anydata[][]|csv:Error result2 = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); diff --git a/ballerina/types.bal b/ballerina/types.bal index 4ce205d..24096a1 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -63,8 +63,6 @@ public type ParseOptions record {| # Represents options for treating a list as a record. public type ParseListOptions record {| *Options; - # If `true`, enables conversion of strings during processing. - boolean stringConversion = true; # If `0`, all the sources will treat as data rows. # Otherwise specify the header rows(Starts from 1) int:Unsigned32 headerRows = 0; @@ -91,7 +89,6 @@ public enum LineTerminator { # Enum representing possible nil values. public enum NilValue { NULL = "null", - EMPTY_STRING = "", NOT_APPLICABLE = "N/A", BAL_NULL = "()" }; diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java index 49fb17c..619e01d 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java @@ -98,7 +98,9 @@ public static Object transform(BArray csv, BMap options, BTyped } public static Object parseList(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createParseListOptions(options), type); + CsvConfig config = CsvConfig.createParseListOptions(options); + config.stringConversion = true; + return CsvTraversal.traverse(csv, config, type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java index 9893d02..dd6bd56 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java @@ -42,7 +42,7 @@ private CsvConfig(CsvConfig config) { this.locale = config.locale; } - public static CsvConfig createParseListsOptions(BMap options) { + public static CsvConfig createParseListOptions(BMap options) { updateDataProjectOptions(options); return new CsvConfig( options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), @@ -51,7 +51,6 @@ public static CsvConfig createParseListsOptions(BMap options) { options.get(Constants.ConfigConstants.SKIP_LINES), options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION), options.getBooleanValue(Constants.ConfigConstants.OUTPUT_WITH_HEADERS), - options.getBooleanValue(Constants.ConfigConstants.STRING_CONVERSION), options.getIntValue(Constants.ConfigConstants.HEADER_ROWS), options.get(Constants.ConfigConstants.CUSTOM_HEADERS) ); @@ -59,14 +58,13 @@ public static CsvConfig createParseListsOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - boolean stringConversion, long headerRows, Object headers) { + long headerRows, Object headers) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.stringConversion = stringConversion; this.headerRows = headerRows; this.customHeaders = headers; }