diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/pest_derive/tests | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/pest_derive/tests')
-rw-r--r-- | vendor/pest_derive/tests/grammar.pest | 83 | ||||
-rw-r--r-- | vendor/pest_derive/tests/grammar.rs | 951 | ||||
-rw-r--r-- | vendor/pest_derive/tests/grammar_inline.rs | 26 | ||||
-rw-r--r-- | vendor/pest_derive/tests/lists.pest | 18 | ||||
-rw-r--r-- | vendor/pest_derive/tests/lists.rs | 121 | ||||
-rw-r--r-- | vendor/pest_derive/tests/reporting.pest | 27 | ||||
-rw-r--r-- | vendor/pest_derive/tests/reporting.rs | 125 |
7 files changed, 1351 insertions, 0 deletions
diff --git a/vendor/pest_derive/tests/grammar.pest b/vendor/pest_derive/tests/grammar.pest new file mode 100644 index 000000000..43a7b8cfd --- /dev/null +++ b/vendor/pest_derive/tests/grammar.pest @@ -0,0 +1,83 @@ +// pest. The Elegant Parser +// Copyright (c) 2018 Dragoș Tiselice +// +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +string = { "abc" } +insensitive = { ^"abc" } +range = { '0'..'9' } +ident = { string } +pos_pred = { &string } +neg_pred = { !string } +double_neg_pred = { !!string } +sequence = !{ string ~ string } +sequence_compound = ${ string ~ string } +sequence_atomic = @{ string ~ string } +sequence_non_atomic = @{ sequence } +sequence_atomic_compound = @{ sequence_compound } +sequence_nested = { string ~ string } +sequence_compound_nested = ${ sequence_nested } +choice = { string | range } +optional = { string? } +repeat = { string* } +repeat_atomic = @{ string* } +repeat_once = { string+ } +repeat_once_atomic = @{ string+ } +repeat_min_max = { string{2, 3} } +repeat_min_max_atomic = @{ string{2, 3} } +repeat_exact = { string{2} } +repeat_min = { string{2,} } +repeat_min_atomic = @{ string{2,} } +repeat_max = { string{, 2} } +repeat_max_atomic = @{ string{, 2} } +soi_at_start = { SOI ~ string } +repeat_mutate_stack = { (PUSH('a'..'c') ~ ",")* ~ POP ~ POP ~ POP } +peek_ = { PUSH(range) ~ PUSH(range) ~ PEEK ~ PEEK } +peek_all = { PUSH(range) ~ PUSH(range) ~ PEEK_ALL } +peek_slice_23 = { PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PEEK[1..-2] } +pop_ = { PUSH(range) ~ PUSH(range) ~ POP ~ POP } +pop_all = { PUSH(range) ~ PUSH(range) ~ POP_ALL } +pop_fail = { PUSH(range) ~ !POP ~ range ~ POP } +checkpoint_restore = ${ + PUSH("") ~ (PUSH("a") ~ "b" ~ POP | DROP ~ "b" | POP ~ "a") ~ EOI +} +ascii_digits = { ASCII_DIGIT+ } +ascii_nonzero_digits = { ASCII_NONZERO_DIGIT+ } +ascii_bin_digits = { ASCII_BIN_DIGIT+ } +ascii_oct_digits = { ASCII_OCT_DIGIT+ } +ascii_hex_digits = { ASCII_HEX_DIGIT+ } +ascii_alpha_lowers = { ASCII_ALPHA_LOWER+ } +ascii_alpha_uppers = { ASCII_ALPHA_UPPER+ } +ascii_alphas = { ASCII_ALPHA+ } +ascii_alphanumerics = { ASCII_ALPHANUMERIC+ } +asciis = { ASCII+ } +newline = { NEWLINE+ } +unicode = { XID_START ~ XID_CONTINUE* } +SYMBOL = { "shadows builtin" } + +WHITESPACE = _{ " " } +COMMENT = _{ "$"+ } + +// Line comment + +/* 1-line multiline comment */ + +/* + N-line multiline comment +*/ + +/* + // Line comment inside multiline + + /* + (Multiline inside) multiline + */ + + Invalid segment of grammar below (repeated rule) + + WHITESPACE = _{ "hi" } +*/ diff --git a/vendor/pest_derive/tests/grammar.rs b/vendor/pest_derive/tests/grammar.rs new file mode 100644 index 000000000..799beb7e0 --- /dev/null +++ b/vendor/pest_derive/tests/grammar.rs @@ -0,0 +1,951 @@ +// pest. The Elegant Parser +// Copyright (c) 2018 Dragoș Tiselice +// +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +#[macro_use] +extern crate pest; +#[macro_use] +extern crate pest_derive; + +#[derive(Parser)] +#[grammar = "../tests/grammar.pest"] +struct GrammarParser; + +#[test] +fn string() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::string, + tokens: [ + string(0, 3) + ] + }; +} + +#[test] +fn insensitive() { + parses_to! { + parser: GrammarParser, + input: "aBC", + rule: Rule::insensitive, + tokens: [ + insensitive(0, 3) + ] + }; +} + +#[test] +fn range() { + parses_to! { + parser: GrammarParser, + input: "6", + rule: Rule::range, + tokens: [ + range(0, 1) + ] + }; +} + +#[test] +fn ident() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::ident, + tokens: [ + ident(0, 3, [ + string(0, 3) + ]) + ] + }; +} + +#[test] +fn pos_pred() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::pos_pred, + tokens: [ + pos_pred(0, 0) + ] + }; +} + +#[test] +fn neg_pred() { + parses_to! { + parser: GrammarParser, + input: "", + rule: Rule::neg_pred, + tokens: [ + neg_pred(0, 0) + ] + }; +} + +#[test] +fn double_neg_pred() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::double_neg_pred, + tokens: [ + double_neg_pred(0, 0) + ] + }; +} + +#[test] +fn sequence() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::sequence, + tokens: [ + sequence(0, 9, [ + string(0, 3), + string(6, 9) + ]) + ] + }; +} + +#[test] +fn sequence_compound() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::sequence_compound, + tokens: [ + sequence_compound(0, 6, [ + string(0, 3), + string(3, 6) + ]) + ] + }; +} + +#[test] +fn sequence_atomic() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::sequence_atomic, + tokens: [ + sequence_atomic(0, 6) + ] + }; +} + +#[test] +fn sequence_non_atomic() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::sequence_non_atomic, + tokens: [ + sequence_non_atomic(0, 9, [ + sequence(0, 9, [ + string(0, 3), + string(6, 9) + ]) + ]) + ] + }; +} + +#[test] +#[should_panic] +fn sequence_atomic_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::sequence_atomic, + tokens: [] + }; +} + +#[test] +fn sequence_atomic_compound() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::sequence_atomic_compound, + tokens: [ + sequence_atomic_compound(0, 6, [ + sequence_compound(0, 6, [ + string(0, 3), + string(3, 6) + ]) + ]) + ] + }; +} + +#[test] +fn sequence_compound_nested() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::sequence_compound_nested, + tokens: [ + sequence_compound_nested(0, 6, [ + sequence_nested(0, 6, [ + string(0, 3), + string(3, 6) + ]) + ]) + ] + }; +} + +#[test] +#[should_panic] +fn sequence_compound_nested_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::sequence_compound_nested, + tokens: [] + }; +} + +#[test] +fn choice_string() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::choice, + tokens: [ + choice(0, 3, [ + string(0, 3) + ]) + ] + }; +} + +#[test] +fn choice_range() { + parses_to! { + parser: GrammarParser, + input: "0", + rule: Rule::choice, + tokens: [ + choice(0, 1, [ + range(0, 1) + ]) + ] + }; +} + +#[test] +fn optional_string() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::optional, + tokens: [ + optional(0, 3, [ + string(0, 3) + ]) + ] + }; +} + +#[test] +fn optional_empty() { + parses_to! { + parser: GrammarParser, + input: "", + rule: Rule::optional, + tokens: [ + optional(0, 0) + ] + }; +} + +#[test] +fn repeat_empty() { + parses_to! { + parser: GrammarParser, + input: "", + rule: Rule::repeat, + tokens: [ + repeat(0, 0) + ] + }; +} + +#[test] +fn repeat_strings() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat, + tokens: [ + repeat(0, 9, [ + string(0, 3), + string(6, 9) + ]) + ] + }; +} + +#[test] +fn repeat_atomic_empty() { + parses_to! { + parser: GrammarParser, + input: "", + rule: Rule::repeat_atomic, + tokens: [ + repeat_atomic(0, 0) + ] + }; +} + +#[test] +fn repeat_atomic_strings() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::repeat_atomic, + tokens: [ + repeat_atomic(0, 6) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_atomic_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_atomic, + tokens: [] + }; +} + +#[test] +#[should_panic] +fn repeat_once_empty() { + parses_to! { + parser: GrammarParser, + input: "", + rule: Rule::repeat_once, + tokens: [] + }; +} + +#[test] +fn repeat_once_strings() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_once, + tokens: [ + repeat_once(0, 9, [ + string(0, 3), + string(6, 9) + ]) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_once_atomic_empty() { + parses_to! { + parser: GrammarParser, + input: "", + rule: Rule::repeat_once_atomic, + tokens: [] + }; +} + +#[test] +fn repeat_once_atomic_strings() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::repeat_once_atomic, + tokens: [ + repeat_once_atomic(0, 6) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_once_atomic_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_once_atomic, + tokens: [] + }; +} + +#[test] +fn repeat_min_max_twice() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_min_max, + tokens: [ + repeat_min_max(0, 7, [ + string(0, 3), + string(4, 7) + ]) + ] + }; +} + +#[test] +fn repeat_min_max_thrice() { + parses_to! { + parser: GrammarParser, + input: "abc abc abc", + rule: Rule::repeat_min_max, + tokens: [ + repeat_min_max(0, 11, [ + string(0, 3), + string(4, 7), + string(8, 11) + ]) + ] + }; +} + +#[test] +fn repeat_min_max_atomic_twice() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::repeat_min_max_atomic, + tokens: [ + repeat_min_max_atomic(0, 6) + ] + }; +} + +#[test] +fn repeat_min_max_atomic_thrice() { + parses_to! { + parser: GrammarParser, + input: "abcabcabc", + rule: Rule::repeat_min_max_atomic, + tokens: [ + repeat_min_max_atomic(0, 9) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_min_max_atomic_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_min_max_atomic, + tokens: [] + }; +} + +#[test] +fn repeat_exact() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_exact, + tokens: [ + repeat_exact(0, 7, [ + string(0, 3), + string(4, 7) + ]) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_min_once() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::repeat_min, + tokens: [] + }; +} + +#[test] +fn repeat_min_twice() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_min, + tokens: [ + repeat_min(0, 7, [ + string(0, 3), + string(4, 7) + ]) + ] + }; +} + +#[test] +fn repeat_min_thrice() { + parses_to! { + parser: GrammarParser, + input: "abc abc abc", + rule: Rule::repeat_min, + tokens: [ + repeat_min(0, 12, [ + string(0, 3), + string(4, 7), + string(9, 12) + ]) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_min_atomic_once() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::repeat_min_atomic, + tokens: [] + }; +} + +#[test] +fn repeat_min_atomic_twice() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::repeat_min_atomic, + tokens: [ + repeat_min_atomic(0, 6) + ] + }; +} + +#[test] +fn repeat_min_atomic_thrice() { + parses_to! { + parser: GrammarParser, + input: "abcabcabc", + rule: Rule::repeat_min_atomic, + tokens: [ + repeat_min_atomic(0, 9) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_min_atomic_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_min_atomic, + tokens: [] + }; +} + +#[test] +fn repeat_max_once() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::repeat_max, + tokens: [ + repeat_max(0, 3, [ + string(0, 3) + ]) + ] + }; +} + +#[test] +fn repeat_max_twice() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_max, + tokens: [ + repeat_max(0, 7, [ + string(0, 3), + string(4, 7) + ]) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_max_thrice() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_max, + tokens: [] + }; +} + +#[test] +fn repeat_max_atomic_once() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::repeat_max_atomic, + tokens: [ + repeat_max_atomic(0, 3) + ] + }; +} + +#[test] +fn repeat_max_atomic_twice() { + parses_to! { + parser: GrammarParser, + input: "abcabc", + rule: Rule::repeat_max_atomic, + tokens: [ + repeat_max_atomic(0, 6) + ] + }; +} + +#[test] +#[should_panic] +fn repeat_max_atomic_thrice() { + parses_to! { + parser: GrammarParser, + input: "abcabcabc", + rule: Rule::repeat_max_atomic, + tokens: [] + }; +} + +#[test] +#[should_panic] +fn repeat_max_atomic_space() { + parses_to! { + parser: GrammarParser, + input: "abc abc", + rule: Rule::repeat_max_atomic, + tokens: [] + }; +} + +#[test] +fn repeat_comment() { + parses_to! { + parser: GrammarParser, + input: "abc$$$ $$$abc", + rule: Rule::repeat_once, + tokens: [ + repeat_once(0, 13, [ + string(0, 3), + string(10, 13) + ]) + ] + }; +} + +#[test] +fn soi_at_start() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::soi_at_start, + tokens: [ + soi_at_start(0, 3, [ + string(0, 3) + ]) + ] + }; +} + +#[test] +fn peek() { + parses_to! { + parser: GrammarParser, + input: "0111", + rule: Rule::peek_, + tokens: [ + peek_(0, 4, [ + range(0, 1), + range(1, 2) + ]) + ] + }; +} + +#[test] +fn peek_all() { + parses_to! { + parser: GrammarParser, + input: "0110", + rule: Rule::peek_all, + tokens: [ + peek_all(0, 4, [ + range(0, 1), + range(1, 2) + ]) + ] + }; +} + +#[test] +fn peek_slice_23() { + parses_to! { + parser: GrammarParser, + input: "0123412", + rule: Rule::peek_slice_23, + tokens: [ + peek_slice_23(0, 7, [ + range(0, 1), + range(1, 2), + range(2, 3), + range(3, 4), + range(4, 5), + ]) + ] + }; +} + +#[test] +fn pop() { + parses_to! { + parser: GrammarParser, + input: "0110", + rule: Rule::pop_, + tokens: [ + pop_(0, 4, [ + range(0, 1), + range(1, 2) + ]) + ] + }; +} + +#[test] +fn pop_all() { + parses_to! { + parser: GrammarParser, + input: "0110", + rule: Rule::pop_all, + tokens: [ + pop_all(0, 4, [ + range(0, 1), + range(1, 2) + ]) + ] + }; +} + +#[test] +fn pop_fail() { + parses_to! { + parser: GrammarParser, + input: "010", + rule: Rule::pop_fail, + tokens: [ + pop_fail(0, 3, [ + range(0, 1), + range(1, 2) + ]) + ] + }; +} + +#[test] +fn repeat_mutate_stack() { + parses_to! { + parser: GrammarParser, + input: "a,b,c,cba", + rule: Rule::repeat_mutate_stack, + tokens: [ + repeat_mutate_stack(0, 9) + ] + }; +} + +#[test] +fn checkpoint_restore() { + parses_to! { + parser: GrammarParser, + input: "a", + rule: Rule::checkpoint_restore, + tokens: [ + checkpoint_restore(0, 1, [EOI(1, 1)]) + ] + }; +} + +#[test] +fn ascii_digits() { + parses_to! { + parser: GrammarParser, + input: "6", + rule: Rule::ascii_digits, + tokens: [ + ascii_digits(0, 1) + ] + }; +} + +#[test] +fn ascii_nonzero_digits() { + parses_to! { + parser: GrammarParser, + input: "5", + rule: Rule::ascii_nonzero_digits, + tokens: [ + ascii_nonzero_digits(0, 1) + ] + }; +} + +#[test] +fn ascii_bin_digits() { + parses_to! { + parser: GrammarParser, + input: "1", + rule: Rule::ascii_bin_digits, + tokens: [ + ascii_bin_digits(0, 1) + ] + }; +} + +#[test] +fn ascii_oct_digits() { + parses_to! { + parser: GrammarParser, + input: "3", + rule: Rule::ascii_oct_digits, + tokens: [ + ascii_oct_digits(0, 1) + ] + }; +} + +#[test] +fn ascii_hex_digits() { + parses_to! { + parser: GrammarParser, + input: "6bC", + rule: Rule::ascii_hex_digits, + tokens: [ + ascii_hex_digits(0, 3) + ] + }; +} + +#[test] +fn ascii_alpha_lowers() { + parses_to! { + parser: GrammarParser, + input: "a", + rule: Rule::ascii_alpha_lowers, + tokens: [ + ascii_alpha_lowers(0, 1) + ] + }; +} + +#[test] +fn ascii_alpha_uppers() { + parses_to! { + parser: GrammarParser, + input: "K", + rule: Rule::ascii_alpha_uppers, + tokens: [ + ascii_alpha_uppers(0, 1) + ] + }; +} + +#[test] +fn ascii_alphas() { + parses_to! { + parser: GrammarParser, + input: "wF", + rule: Rule::ascii_alphas, + tokens: [ + ascii_alphas(0, 2) + ] + }; +} + +#[test] +fn ascii_alphanumerics() { + parses_to! { + parser: GrammarParser, + input: "4jU", + rule: Rule::ascii_alphanumerics, + tokens: [ + ascii_alphanumerics(0, 3) + ] + }; +} + +#[test] +fn asciis() { + parses_to! { + parser: GrammarParser, + input: "x02", + rule: Rule::asciis, + tokens: [ + asciis(0, 3) + ] + }; +} + +#[test] +fn newline() { + parses_to! { + parser: GrammarParser, + input: "\n\r\n\r", + rule: Rule::newline, + tokens: [ + newline(0, 4) + ] + }; +} + +#[test] +fn unicode() { + parses_to! { + parser: GrammarParser, + input: "نامهای", + rule: Rule::unicode, + tokens: [ + unicode(0, 12) + ] + } +} + +#[test] +fn shadowing() { + parses_to! { + parser: GrammarParser, + input: "shadows builtin", + rule: Rule::SYMBOL, + tokens: [ + SYMBOL(0, 15) + ] + } +} diff --git a/vendor/pest_derive/tests/grammar_inline.rs b/vendor/pest_derive/tests/grammar_inline.rs new file mode 100644 index 000000000..2cc730afc --- /dev/null +++ b/vendor/pest_derive/tests/grammar_inline.rs @@ -0,0 +1,26 @@ +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +#[macro_use] +extern crate pest; +#[macro_use] +extern crate pest_derive; + +#[derive(Parser)] +#[grammar_inline = "string = { \"abc\" }"] +struct GrammarParser; + +#[test] +fn inline_string() { + parses_to! { + parser: GrammarParser, + input: "abc", + rule: Rule::string, + tokens: [ + string(0, 3) + ] + }; +} diff --git a/vendor/pest_derive/tests/lists.pest b/vendor/pest_derive/tests/lists.pest new file mode 100644 index 000000000..47756b764 --- /dev/null +++ b/vendor/pest_derive/tests/lists.pest @@ -0,0 +1,18 @@ +// pest. The Elegant Parser +// Copyright (c) 2018 Dragoș Tiselice +// +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +item = { (!"\n" ~ ANY)* } + +lists = _{ lines ~ EOI } +lines = _{ top_first ~ ("\n" ~ top_continue)* } +top_first = _{ "- " ~ item ~ ("\n" ~ children)? } +top_continue = _{ PEEK_ALL ~ "- " ~ item ~ ("\n" ~ children)? } + +indentation = _{ (" " | "\t")+ } +children = { PEEK_ALL ~ PUSH(indentation) ~ lines ~ DROP } diff --git a/vendor/pest_derive/tests/lists.rs b/vendor/pest_derive/tests/lists.rs new file mode 100644 index 000000000..4ba0effce --- /dev/null +++ b/vendor/pest_derive/tests/lists.rs @@ -0,0 +1,121 @@ +// pest. The Elegant Parser +// Copyright (c) 2018 Dragoș Tiselice +// +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +#[macro_use] +extern crate pest; +#[macro_use] +extern crate pest_derive; + +#[derive(Parser)] +#[grammar = "../tests/lists.pest"] +struct ListsParser; + +#[test] +fn item() { + parses_to! { + parser: ListsParser, + input: "- a", + rule: Rule::lists, + tokens: [ + item(2, 3) + ] + }; +} + +#[test] +fn items() { + parses_to! { + parser: ListsParser, + input: "- a\n- b", + rule: Rule::lists, + tokens: [ + item(2, 3), + item(6, 7) + ] + }; +} + +#[test] +fn children() { + parses_to! { + parser: ListsParser, + input: " - b", + rule: Rule::children, + tokens: [ + children(0, 5, [ + item(4, 5) + ]) + ] + }; +} + +#[test] +fn nested_item() { + parses_to! { + parser: ListsParser, + input: "- a\n - b", + rule: Rule::lists, + tokens: [ + item(2, 3), + children(4, 9, [ + item(8, 9) + ]) + ] + }; +} + +#[test] +fn nested_items() { + parses_to! { + parser: ListsParser, + input: "- a\n - b\n - c", + rule: Rule::lists, + tokens: [ + item(2, 3), + children(4, 15, [ + item(8, 9), + item(14, 15) + ]) + ] + }; +} + +#[test] +fn nested_two_levels() { + parses_to! { + parser: ListsParser, + input: "- a\n - b\n - c", + rule: Rule::lists, + tokens: [ + item(2, 3), + children(4, 17, [ + item(8, 9), + children(10, 17, [ + item(16, 17) + ]) + ]) + ] + }; +} + +#[test] +fn nested_then_not() { + parses_to! { + parser: ListsParser, + input: "- a\n - b\n- c", + rule: Rule::lists, + tokens: [ + item(2, 3), + children(4, 9, [ + item(8, 9) + ]), + item(12, 13) + ] + }; +} diff --git a/vendor/pest_derive/tests/reporting.pest b/vendor/pest_derive/tests/reporting.pest new file mode 100644 index 000000000..060dbfc20 --- /dev/null +++ b/vendor/pest_derive/tests/reporting.pest @@ -0,0 +1,27 @@ +// pest. The Elegant Parser +// Copyright (c) 2018 Dragoș Tiselice +// +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +a = { "a" } +b = { "b" } +c = { "c" } +d = { ANY } + +choices = _{ a | b | c } +choices_no_progress = { a | b | c } +choices_a_progress = { a ~ a | b | c } +choices_b_progress = { a | b ~ b | c } + +level1 = _{ level2 } +level2 = _{ a | b | c } + +negative = _{ !d } +negative_match = _{ !a ~ b } +mixed = _{ !d | a } +mixed_progress = _{ (!d | a | b) ~ a } + diff --git a/vendor/pest_derive/tests/reporting.rs b/vendor/pest_derive/tests/reporting.rs new file mode 100644 index 000000000..aa0a974e0 --- /dev/null +++ b/vendor/pest_derive/tests/reporting.rs @@ -0,0 +1,125 @@ +// pest. The Elegant Parser +// Copyright (c) 2018 Dragoș Tiselice +// +// Licensed under the Apache License, Version 2.0 +// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT +// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. + +#[macro_use] +extern crate pest; +#[macro_use] +extern crate pest_derive; + +#[derive(Parser)] +#[grammar = "../tests/reporting.pest"] +struct ReportingParser; + +#[test] +fn choices() { + fails_with! { + parser: ReportingParser, + input: "x", + rule: Rule::choices, + positives: vec![Rule::a, Rule::b, Rule::c], + negatives: vec![], + pos: 0 + }; +} + +#[test] +fn choices_no_progress() { + fails_with! { + parser: ReportingParser, + input: "x", + rule: Rule::choices_no_progress, + positives: vec![Rule::choices_no_progress], + negatives: vec![], + pos: 0 + }; +} + +#[test] +fn choices_a_progress() { + fails_with! { + parser: ReportingParser, + input: "a", + rule: Rule::choices_a_progress, + positives: vec![Rule::a], + negatives: vec![], + pos: 1 + }; +} + +#[test] +fn choices_b_progress() { + fails_with! { + parser: ReportingParser, + input: "b", + rule: Rule::choices_b_progress, + positives: vec![Rule::b], + negatives: vec![], + pos: 1 + }; +} + +#[test] +fn nested() { + fails_with! { + parser: ReportingParser, + input: "x", + rule: Rule::level1, + positives: vec![Rule::a, Rule::b, Rule::c], + negatives: vec![], + pos: 0 + }; +} + +#[test] +fn negative() { + fails_with! { + parser: ReportingParser, + input: "x", + rule: Rule::negative, + positives: vec![], + negatives: vec![Rule::d], + pos: 0 + }; +} + +#[test] +fn negative_match() { + fails_with! { + parser: ReportingParser, + input: "x", + rule: Rule::negative_match, + positives: vec![Rule::b], + negatives: vec![], + pos: 0 + }; +} + +#[test] +fn mixed() { + fails_with! { + parser: ReportingParser, + input: "x", + rule: Rule::mixed, + positives: vec![Rule::a], + negatives: vec![Rule::d], + pos: 0 + }; +} + +#[test] +fn mixed_progress() { + fails_with! { + parser: ReportingParser, + input: "b", + rule: Rule::mixed_progress, + positives: vec![Rule::a], + negatives: vec![], + pos: 1 + }; +} |