@@ -717,131 +717,87 @@ world`},
717
717
}
718
718
}
719
719
720
- const errorTests = `
721
- foo.
722
- unexpected end of expression (1:4)
720
+ func TestParse_error (t * testing.T ) {
721
+ var tests = []struct {
722
+ input string
723
+ err string
724
+ }{
725
+ {`foo.` , `unexpected end of expression (1:4)
723
726
| foo.
724
- | ...^
725
-
726
- a+
727
- unexpected token EOF (1:2)
727
+ | ...^` },
728
+ {`a+` , `unexpected token EOF (1:2)
728
729
| a+
729
- | .^
730
-
731
- a ? (1+2) c
732
- unexpected token Identifier("c") (1:11)
730
+ | .^` },
731
+ {`a ? (1+2) c` , `unexpected token Identifier("c") (1:11)
733
732
| a ? (1+2) c
734
- | ..........^
735
-
736
- [a b]
737
- unexpected token Identifier("b") (1:4)
733
+ | ..........^` },
734
+ {`[a b]` , `unexpected token Identifier("b") (1:4)
738
735
| [a b]
739
- | ...^
740
-
741
- foo.bar(a b)
742
- unexpected token Identifier("b") (1:11)
736
+ | ...^` },
737
+ {`foo.bar(a b)` , `unexpected token Identifier("b") (1:11)
743
738
| foo.bar(a b)
744
- | ..........^
745
-
746
- {-}
747
- a map key must be a quoted string, a number, a identifier, or an expression enclosed in parentheses (unexpected token Operator("-")) (1:2)
739
+ | ..........^` },
740
+ {`{-}` , `a map key must be a quoted string, a number, a identifier, or an expression enclosed in parentheses (unexpected token Operator("-")) (1:2)
748
741
| {-}
749
- | .^
750
-
751
- foo({.bar})
752
- a map key must be a quoted string, a number, a identifier, or an expression enclosed in parentheses (unexpected token Operator(".")) (1:6)
742
+ | .^` },
743
+ {`foo({.bar})` , `a map key must be a quoted string, a number, a identifier, or an expression enclosed in parentheses (unexpected token Operator(".")) (1:6)
753
744
| foo({.bar})
754
- | .....^
755
-
756
- .foo
757
- cannot use pointer accessor outside predicate (1:1)
745
+ | .....^` },
746
+ {`.foo` , `cannot use pointer accessor outside predicate (1:1)
758
747
| .foo
759
- | ^
760
-
761
- [1, 2, 3,,]
762
- unexpected token Operator(",") (1:10)
748
+ | ^` },
749
+ {`[1, 2, 3,,]` , `unexpected token Operator(",") (1:10)
763
750
| [1, 2, 3,,]
764
- | .........^
765
-
766
- [,]
767
- unexpected token Operator(",") (1:2)
751
+ | .........^` },
752
+ {`[,]` , `unexpected token Operator(",") (1:2)
768
753
| [,]
769
- | .^
770
-
771
- {,}
772
- a map key must be a quoted string, a number, a identifier, or an expression enclosed in parentheses (unexpected token Operator(",")) (1:2)
754
+ | .^` },
755
+ {`{,}` , `a map key must be a quoted string, a number, a identifier, or an expression enclosed in parentheses (unexpected token Operator(",")) (1:2)
773
756
| {,}
774
- | .^
775
-
776
- {foo:1, bar:2, ,}
777
- unexpected token Operator(",") (1:16)
757
+ | .^` },
758
+ {`{foo:1, bar:2, ,}` , `unexpected token Operator(",") (1:16)
778
759
| {foo:1, bar:2, ,}
779
- | ...............^
780
-
781
- foo ?? bar || baz
782
- Operator (||) and coalesce expressions (??) cannot be mixed. Wrap either by parentheses. (1:12)
760
+ | ...............^` },
761
+ {`foo ?? bar || baz` , `Operator (||) and coalesce expressions (??) cannot be mixed. Wrap either by parentheses. (1:12)
783
762
| foo ?? bar || baz
784
- | ...........^
785
-
786
- 0b15
787
- bad number syntax: "0b15" (1:4)
763
+ | ...........^` },
764
+ {`0b15` , `bad number syntax: "0b15" (1:4)
788
765
| 0b15
789
- | ...^
790
-
791
- 0X10G
792
- bad number syntax: "0X10G" (1:5)
766
+ | ...^` },
767
+ {`0X10G` , `bad number syntax: "0X10G" (1:5)
793
768
| 0X10G
794
- | ....^
795
-
796
- 0o1E
797
- invalid float literal: strconv.ParseFloat: parsing "0o1E": invalid syntax (1:4)
769
+ | ....^` },
770
+ {`0o1E` , `invalid float literal: strconv.ParseFloat: parsing "0o1E": invalid syntax (1:4)
798
771
| 0o1E
799
- | ...^
800
-
801
- 0b1E
802
- invalid float literal: strconv.ParseFloat: parsing "0b1E": invalid syntax (1:4)
772
+ | ...^` },
773
+ {`0b1E` , `invalid float literal: strconv.ParseFloat: parsing "0b1E": invalid syntax (1:4)
803
774
| 0b1E
804
- | ...^
805
-
806
- 0b1E+6
807
- bad number syntax: "0b1E+6" (1:6)
775
+ | ...^` },
776
+ {`0b1E+6` , `bad number syntax: "0b1E+6" (1:6)
808
777
| 0b1E+6
809
- | .....^
810
-
811
- 0b1E+1
812
- invalid float literal: strconv.ParseFloat: parsing "0b1E+1": invalid syntax (1:6)
778
+ | .....^` },
779
+ {`0b1E+1` , `invalid float literal: strconv.ParseFloat: parsing "0b1E+1": invalid syntax (1:6)
813
780
| 0b1E+1
814
- | .....^
815
-
816
- 0o1E+1
817
- invalid float literal: strconv.ParseFloat: parsing "0o1E+1": invalid syntax (1:6)
781
+ | .....^` },
782
+ {`0o1E+1` , `invalid float literal: strconv.ParseFloat: parsing "0o1E+1": invalid syntax (1:6)
818
783
| 0o1E+1
819
- | .....^
820
-
821
- 1E
822
- invalid float literal: strconv.ParseFloat: parsing "1E": invalid syntax (1:2)
784
+ | .....^` },
785
+ {`1E` , `invalid float literal: strconv.ParseFloat: parsing "1E": invalid syntax (1:2)
823
786
| 1E
824
- | .^
825
-
826
- 1 not == [1, 2, 5]
827
- unexpected token Operator("==") (1:7)
787
+ | .^` },
788
+ {`1 not == [1, 2, 5]` , `unexpected token Operator("==") (1:7)
828
789
| 1 not == [1, 2, 5]
829
- | ......^
830
- `
790
+ | ......^` },
791
+ }
831
792
832
- func TestParse_error (t * testing.T ) {
833
- tests := strings .Split (strings .Trim (errorTests , "\n " ), "\n \n " )
834
793
for _ , test := range tests {
835
- input := strings .SplitN (test , "\n " , 2 )
836
- if len (input ) != 2 {
837
- t .Errorf ("syntax error in test: %q" , test )
838
- break
839
- }
840
- _ , err := parser .Parse (input [0 ])
841
- if err == nil {
842
- err = fmt .Errorf ("<nil>" )
843
- }
844
- assert .Equal (t , input [1 ], err .Error (), input [0 ])
794
+ t .Run (test .input , func (t * testing.T ) {
795
+ _ , err := parser .Parse (test .input )
796
+ if err == nil {
797
+ err = fmt .Errorf ("<nil>" )
798
+ }
799
+ assert .Equal (t , test .err , err .Error (), test .input )
800
+ })
845
801
}
846
802
}
847
803
0 commit comments