Repository: apollographql/apollo-rs
Pull request #231 (2022-05-24 09:59:29)

chore(parser): add extra tests for 227
adds a few more variants for escaping in string values


Patch:
diff --git a/crates/apollo-parser/src/parser/grammar/value.rs b/crates/apollo-parser/src/parser/grammar/value.rs
index a387658..8e57fec 100644
--- a/crates/apollo-parser/src/parser/grammar/value.rs
+++ b/crates/apollo-parser/src/parser/grammar/value.rs
@@ -207,7 +207,7 @@ enum Test @dir__one(int_value: -10) {
     #[allow(clippy::float_cmp)]
     fn it_returns_f64_for_float_values() {
         let schema = r#"
-enum Test @dir__one(float_value: -1.123E4) { 
+enum Test @dir__one(float_value: -1.123E4) {
   INVENTORY
 } "#;
         let parser = Parser::new(schema);
@@ -235,7 +235,7 @@ enum Test @dir__one(float_value: -1.123E4) {
     #[test]
     fn it_returns_bool_for_boolean_values() {
         let schema = r#"
-enum Test @dir__one(bool_value: false) { 
+enum Test @dir__one(bool_value: false) {
   INVENTORY
 } "#;
         let parser = Parser::new(schema);


Test patch:
diff --git a/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.graphql b/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.graphql
index fe7e418..1e9af54 100644
--- a/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.graphql
+++ b/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.graphql
@@ -1,1 +1,5 @@
-{ name: "\my store\"" }
\ No newline at end of file
+{
+    sku: "\a invalidly escaped"
+    stringValue: "\"properly escaped\""
+    name: "\invalidly escaped\""
+}
\ No newline at end of file
diff --git a/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.txt b/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.txt
index 12a6420..37b60b5 100644
--- a/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.txt
+++ b/crates/apollo-parser/test_data/lexer/err/0005_escaped_char.txt
@@ -1,9 +1,19 @@
 L_CURLY@0:1 "{"
-WHITESPACE@1:2 " "
-NAME@2:6 "name"
-COLON@6:7 ":"
-WHITESPACE@7:8 " "
-WHITESPACE@21:22 " "
-R_CURLY@22:23 "}"
-EOF@23:23
-ERROR@8:21 "unexpected escaped character" "\my store\""
+WHITESPACE@1:6 "\n    "
+NAME@6:9 "sku"
+COLON@9:10 ":"
+WHITESPACE@10:11 " "
+WHITESPACE@33:38 "\n    "
+NAME@38:49 "stringValue"
+COLON@49:50 ":"
+WHITESPACE@50:51 " "
+STRING_VALUE@51:73 "\"\\\"properly escaped\\\"\""
+WHITESPACE@73:78 "\n    "
+NAME@78:82 "name"
+COLON@82:83 ":"
+WHITESPACE@83:84 " "
+WHITESPACE@106:107 "\n"
+R_CURLY@107:108 "}"
+EOF@108:108
+ERROR@11:33 "unexpected escaped character" "\a invalidly escaped"
+ERROR@84:106 "unexpected escaped character" "\invalidly escaped\""
diff --git a/crates/apollo-parser/test_data/lexer/ok/0004_string_value.graphql b/crates/apollo-parser/test_data/lexer/ok/0004_string_value.graphql
index 587d330..551111d 100644
--- a/crates/apollo-parser/test_data/lexer/ok/0004_string_value.graphql
+++ b/crates/apollo-parser/test_data/lexer/ok/0004_string_value.graphql
@@ -11,4 +11,5 @@
 "string with maximal minimal unicode escape \\u{00000000}"
 "string with unicode surrogate pair escape \\uD83D\\uDE00"
 "string with minimal surrogate pair escape \\uD800\\uDC00"
-"string with maximal surrogate pair escape \\uDBFF\\uDFFF"
\ No newline at end of file
+"string with maximal surrogate pair escape \\uDBFF\\uDFFF"
+"string with \"escaped\" characters"
\ No newline at end of file
diff --git a/crates/apollo-parser/test_data/lexer/ok/0004_string_value.txt b/crates/apollo-parser/test_data/lexer/ok/0004_string_value.txt
index 3a7507e..64185c3 100644
--- a/crates/apollo-parser/test_data/lexer/ok/0004_string_value.txt
+++ b/crates/apollo-parser/test_data/lexer/ok/0004_string_value.txt
@@ -25,4 +25,6 @@ WHITESPACE@469:470 "\n"
 STRING_VALUE@470:528 "\"string with minimal surrogate pair escape \\\\uD800\\\\uDC00\""
 WHITESPACE@528:529 "\n"
 STRING_VALUE@529:587 "\"string with maximal surrogate pair escape \\\\uDBFF\\\\uDFFF\""
-EOF@587:587
+WHITESPACE@587:588 "\n"
+STRING_VALUE@588:624 "\"string with \\\"escaped\\\" characters\""
+EOF@624:624
diff --git a/crates/apollo-parser/test_data/parser/err/0031_argument_with_erronous_string_value.graphql b/crates/apollo-parser/test_data/parser/err/0031_argument_with_erronous_string_value.graphql
new file mode 100644
index 0000000..0129fc3
--- /dev/null
+++ b/crates/apollo-parser/test_data/parser/err/0031_argument_with_erronous_string_value.graphql
@@ -0,0 +1,3 @@
+{
+  user(id: "\string ID")
+}
\ No newline at end of file
diff --git a/crates/apollo-parser/test_data/parser/err/0031_argument_with_erronous_string_value.txt b/crates/apollo-parser/test_data/parser/err/0031_argument_with_erronous_string_value.txt
new file mode 100644
index 0000000..8a7abef
--- /dev/null
+++ b/crates/apollo-parser/test_data/parser/err/0031_argument_with_erronous_string_value.txt
@@ -0,0 +1,20 @@
+- DOCUMENT@0..16
+    - OPERATION_DEFINITION@0..16
+        - SELECTION_SET@0..16
+            - L_CURLY@0..1 "{"
+            - WHITESPACE@1..4 "\n  "
+            - FIELD@4..15
+                - NAME@4..8
+                    - IDENT@4..8 "user"
+                - ARGUMENTS@8..15
+                    - L_PAREN@8..9 "("
+                    - ARGUMENT@9..13
+                        - NAME@9..11
+                            - IDENT@9..11 "id"
+                        - COLON@11..12 ":"
+                        - WHITESPACE@12..13 " "
+                    - R_PAREN@13..14 ")"
+                    - WHITESPACE@14..15 "\n"
+            - R_CURLY@15..16 "}"
+- ERROR@13:25 "unexpected escaped character" "\string ID"
+- ERROR@25:26 "expected a valid Value" )
diff --git a/crates/apollo-parser/test_data/parser/err/0032_input_value_with_erronous_string_value.graphql b/crates/apollo-parser/test_data/parser/err/0032_input_value_with_erronous_string_value.graphql
new file mode 100644
index 0000000..f963502
--- /dev/null
+++ b/crates/apollo-parser/test_data/parser/err/0032_input_value_with_erronous_string_value.graphql
@@ -0,0 +1,4 @@
+type Person {
+  name: String
+  picture(reference: "\a reference image"): Url
+}
\ No newline at end of file
diff --git a/crates/apollo-parser/test_data/parser/err/0032_input_value_with_erronous_string_value.txt b/crates/apollo-parser/test_data/parser/err/0032_input_value_with_erronous_string_value.txt
new file mode 100644
index 0000000..9118e52
--- /dev/null
+++ b/crates/apollo-parser/test_data/parser/err/0032_input_value_with_erronous_string_value.txt
@@ -0,0 +1,40 @@
+- DOCUMENT@0..58
+    - OBJECT_TYPE_DEFINITION@0..58
+        - type_KW@0..4 "type"
+        - WHITESPACE@4..5 " "
+        - NAME@5..12
+            - IDENT@5..11 "Person"
+            - WHITESPACE@11..12 " "
+        - FIELDS_DEFINITION@12..58
+            - L_CURLY@12..13 "{"
+            - WHITESPACE@13..16 "\n  "
+            - FIELD_DEFINITION@16..31
+                - NAME@16..20
+                    - IDENT@16..20 "name"
+                - COLON@20..21 ":"
+                - WHITESPACE@21..22 " "
+                - NAMED_TYPE@22..28
+                    - NAME@22..28
+                        - IDENT@22..28 "String"
+                - WHITESPACE@28..31 "\n  "
+            - FIELD_DEFINITION@31..57
+                - NAME@31..38
+                    - IDENT@31..38 "picture"
+                - ARGUMENTS_DEFINITION@38..51
+                    - L_PAREN@38..39 "("
+                    - INPUT_VALUE_DEFINITION@39..50
+                        - NAME@39..48
+                            - IDENT@39..48 "reference"
+                        - COLON@48..49 ":"
+                        - WHITESPACE@49..50 " "
+                    - R_PAREN@50..51 ")"
+                - COLON@51..52 ":"
+                - WHITESPACE@52..53 " "
+                - NAMED_TYPE@53..56
+                    - NAME@53..56
+                        - IDENT@53..56 "Url"
+                - WHITESPACE@56..57 "\n"
+            - R_CURLY@57..58 "}"
+- ERROR@50:70 "unexpected escaped character" "\a reference image"
+- ERROR@70:71 "expected a Type" )
+- ERROR@70:71 "expected an Input Value Definition" )
diff --git a/crates/apollo-parser/test_data/parser/err/0033_directive_with_erronous_string_value.graphql b/crates/apollo-parser/test_data/parser/err/0033_directive_with_erronous_string_value.graphql
new file mode 100644
index 0000000..942cf4b
--- /dev/null
+++ b/crates/apollo-parser/test_data/parser/err/0033_directive_with_erronous_string_value.graphql
@@ -0,0 +1,5 @@
+directive @delegateField(name: String!) repeatable on OBJECT | INTERFACE
+
+type Book @delegateField(name: "\ errronous string \""){
+  id: ID!
+}
\ No newline at end of file
diff --git a/crates/apollo-parser/test_data/parser/err/0033_directive_with_erronous_string_value.txt b/crates/apollo-parser/test_data/parser/err/0033_directive_with_erronous_string_value.txt
new file mode 100644
index 0000000..0ac8112
--- /dev/null
+++ b/crates/apollo-parser/test_data/parser/err/0033_directive_with_erronous_string_value.txt
@@ -0,0 +1,70 @@
+- DOCUMENT@0..119
+    - DIRECTIVE_DEFINITION@0..74
+        - directive_KW@0..9 "directive"
+        - WHITESPACE@9..10 " "
+        - AT@10..11 "@"
+        - NAME@11..24
+            - IDENT@11..24 "delegateField"
+        - ARGUMENTS_DEFINITION@24..40
+            - L_PAREN@24..25 "("
+            - INPUT_VALUE_DEFINITION@25..38
+                - NAME@25..29
+                    - IDENT@25..29 "name"
+                - COLON@29..30 ":"
+                - WHITESPACE@30..31 " "
+                - NON_NULL_TYPE@31..38
+                    - NAMED_TYPE@31..37
+                        - NAME@31..37
+                            - IDENT@31..37 "String"
+                    - BANG@37..38 "!"
+            - R_PAREN@38..39 ")"
+            - WHITESPACE@39..40 " "
+        - repeatable_KW@40..50 "repeatable"
+        - WHITESPACE@50..51 " "
+        - on_KW@51..53 "on"
+        - WHITESPACE@53..54 " "
+        - DIRECTIVE_LOCATIONS@54..74
+            - DIRECTIVE_LOCATION@54..61
+                - OBJECT_KW@54..60 "OBJECT"
+                - WHITESPACE@60..61 " "
+            - PIPE@61..62 "|"
+            - WHITESPACE@62..63 " "
+            - DIRECTIVE_LOCATION@63..74
+                - INTERFACE_KW@63..72 "INTERFACE"
+                - WHITESPACE@72..74 "\n\n"
+    - OBJECT_TYPE_DEFINITION@74..119
+        - type_KW@74..78 "type"
+        - WHITESPACE@78..79 " "
+        - NAME@79..84
+            - IDENT@79..83 "Book"
+            - WHITESPACE@83..84 " "
+        - DIRECTIVES@84..106
+            - DIRECTIVE@84..106
+                - AT@84..85 "@"
+                - NAME@85..98
+                    - IDENT@85..98 "delegateField"
+                - ARGUMENTS@98..106
+                    - L_PAREN@98..99 "("
+                    - ARGUMENT@99..105
+                        - NAME@99..103
+                            - IDENT@99..103 "name"
+                        - COLON@103..104 ":"
+                        - WHITESPACE@104..105 " "
+                    - R_PAREN@105..106 ")"
+        - FIELDS_DEFINITION@106..119
+            - L_CURLY@106..107 "{"
+            - WHITESPACE@107..110 "\n  "
+            - FIELD_DEFINITION@110..118
+                - NAME@110..112
+                    - IDENT@110..112 "id"
+                - COLON@112..113 ":"
+                - WHITESPACE@113..114 " "
+                - NON_NULL_TYPE@114..118
+                    - NAMED_TYPE@114..116
+                        - NAME@114..116
+                            - IDENT@114..116 "ID"
+                    - BANG@116..117 "!"
+                    - WHITESPACE@117..118 "\n"
+            - R_CURLY@118..119 "}"
+- ERROR@105:128 "unexpected escaped character" "\ errronous string \""
+- ERROR@128:129 "expected a valid Value" )