aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/andybalholm/cascadia/parser_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/andybalholm/cascadia/parser_test.go')
-rw-r--r--vendor/github.com/andybalholm/cascadia/parser_test.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/vendor/github.com/andybalholm/cascadia/parser_test.go b/vendor/github.com/andybalholm/cascadia/parser_test.go
new file mode 100644
index 0000000..47dd4a6
--- /dev/null
+++ b/vendor/github.com/andybalholm/cascadia/parser_test.go
@@ -0,0 +1,86 @@
+package cascadia
+
+import (
+ "testing"
+)
+
+var identifierTests = map[string]string{
+ "x": "x",
+ "96": "",
+ "-x": "-x",
+ `r\e9 sumé`: "résumé",
+ `a\"b`: `a"b`,
+}
+
+func TestParseIdentifier(t *testing.T) {
+ for source, want := range identifierTests {
+ p := &parser{s: source}
+ got, err := p.parseIdentifier()
+
+ if err != nil {
+ if want == "" {
+ // It was supposed to be an error.
+ continue
+ }
+ t.Errorf("parsing %q: got error (%s), want %q", source, err, want)
+ continue
+ }
+
+ if want == "" {
+ if err == nil {
+ t.Errorf("parsing %q: got %q, want error", source, got)
+ }
+ continue
+ }
+
+ if p.i < len(source) {
+ t.Errorf("parsing %q: %d bytes left over", source, len(source)-p.i)
+ continue
+ }
+
+ if got != want {
+ t.Errorf("parsing %q: got %q, want %q", source, got, want)
+ }
+ }
+}
+
+var stringTests = map[string]string{
+ `"x"`: "x",
+ `'x'`: "x",
+ `'x`: "",
+ "'x\\\r\nx'": "xx",
+ `"r\e9 sumé"`: "résumé",
+ `"a\"b"`: `a"b`,
+}
+
+func TestParseString(t *testing.T) {
+ for source, want := range stringTests {
+ p := &parser{s: source}
+ got, err := p.parseString()
+
+ if err != nil {
+ if want == "" {
+ // It was supposed to be an error.
+ continue
+ }
+ t.Errorf("parsing %q: got error (%s), want %q", source, err, want)
+ continue
+ }
+
+ if want == "" {
+ if err == nil {
+ t.Errorf("parsing %q: got %q, want error", source, got)
+ }
+ continue
+ }
+
+ if p.i < len(source) {
+ t.Errorf("parsing %q: %d bytes left over", source, len(source)-p.i)
+ continue
+ }
+
+ if got != want {
+ t.Errorf("parsing %q: got %q, want %q", source, got, want)
+ }
+ }
+}