chiark / gitweb /
Remove ad hoc tokenization tests in favor of generated ones, remove unused defined...
authorJeff Ober <jober@ziprecruiter.com>
Fri, 17 Jan 2020 17:42:14 +0000 (12:42 -0500)
committerJeff Ober <jober@ziprecruiter.com>
Fri, 17 Jan 2020 17:42:14 +0000 (12:42 -0500)
12 files changed:
lib/TOML/Tiny/Grammar.pm
t/tokens/array-of-tables.t [deleted file]
t/tokens/array.t [deleted file]
t/tokens/boolean.t [deleted file]
t/tokens/datetime.t [deleted file]
t/tokens/float.t [deleted file]
t/tokens/inline-table.t [deleted file]
t/tokens/integer.t [deleted file]
t/tokens/key-value-pair.t [deleted file]
t/tokens/key.t [deleted file]
t/tokens/string.t [deleted file]
t/tokens/table.t [deleted file]

index 1a7e23686b9fbd74f5c9741c1c7dbfc564f01b3d..76ca5a7e1d413a1d20e526f6f4d8bb44595ecf14 100644 (file)
@@ -17,96 +17,10 @@ our $TOML = qr{
   #-----------------------------------------------------------------------------
   # Misc
   #-----------------------------------------------------------------------------
-  (?<Value>
-      (?&Boolean)
-    | (?&DateTime)
-    | (?&Float)
-    | (?&Integer)
-    | (?&String)
-    | (?&Array)
-    | (?&InlineTable)
-  )
-
   (?<WS>   [ \x20 \x09 ]*)         # space, tab
   (?<CRLF> \x0D? \x0A)             # cr? lf
   (?<EOL>  (?: \x23 .*)? (?&CRLF)) # crlf or comment -> crlf
 
-  #-----------------------------------------------------------------------------
-  # Array of tables
-  #-----------------------------------------------------------------------------
-  (?<ArrayOfTables>
-    (?m)
-    (?s)
-
-    \[\[ (?&Key) \]\] (?&EOL)
-
-    (?:
-        (?: (?&KeyValuePair) (?=(?&CRLF)) )
-      | (?&ArrayOfTables)
-      | (?&Table)
-    )*
-
-    (?-s)
-    (?-m)
-  )
-
-  #-----------------------------------------------------------------------------
-  # Table
-  #-----------------------------------------------------------------------------
-  (?<KeyValuePair> (?&Key) (?&WS) = (?&WS) (?&Value))
-  (?<KeyValuePairDecl> (?&Key) (?&WS) = (?&WS) (?&Value) (?&WS) (?&EOL))
-
-  (?<KeyValuePairList>
-      (?&KeyValuePair) (?&WS) (?: [,] (?&WS) (?&KeyValuePairList) )?
-    | (?&KeyValuePair)
-  )
-
-  (?<InlineTable>
-    {
-      (?&WS)
-      (?&KeyValuePairList)
-      (?&WS)
-    }
-  )
-
-  (?<TableDecl> \[ (?&Key) \] (?&EOL))
-
-  (?<Table>
-    (?&TableDecl)
-    (?:
-        (?&KeyValuePairDecl)
-      | (?&ArrayOfTables)
-    )*
-  )
-
-  #-----------------------------------------------------------------------------
-  # Array
-  #-----------------------------------------------------------------------------
-  (?<ListSep>
-    (?&WS)
-    [,]
-    (?&WS)
-    (?&CRLF)?
-    (?&WS)
-  )
-
-  (?<List>
-      (?&Value) (?&ListSep) (?&List)?
-    | (?&Value)
-  )
-
-  (?<Array>
-    \[
-
-    (?&WS) (?&CRLF)? (?&WS)
-
-    (?&List)
-
-    (?&WS) (?&CRLF)? (?&WS)
-
-    \]
-  )
-
   #-----------------------------------------------------------------------------
   # Key
   #-----------------------------------------------------------------------------
diff --git a/t/tokens/array-of-tables.t b/t/tokens/array-of-tables.t
deleted file mode 100644 (file)
index 101eced..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&ArrayOfTables)) $TOML }x;
-
-my @valid = (
-  qq{[[foo]]\n},
-
-  qq{[[foo]]
-bar = 1234},
-
-  qq{[[foo]]
-bar = 1234
-baz = 5678},
-
-  qq{[[foo]]
-bar = 1234
-[[baz]]
-bat = 5678},
-
-  qq{[[foo]]
-bar = 1234
-[baz]
-bat = 5678},
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/array.t b/t/tokens/array.t
deleted file mode 100644 (file)
index b79c007..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&Array)) $TOML }x;
-
-my @valid = (
-  q{[ 1, 2, 3 ]},
-  q{[ "red", "yellow", "green" ]},
-  q{[ [ 1, 2 ], [3, 4, 5] ]},
-  q{[ [ 1, 2 ], ["a", "b", "c"] ]},
-  q{[ "all", 'strings', """are the same""", '''type''' ]},
-  q{[ 0.1, 0.2, 0.5, 1, 2, 5 ]},
-  q{[ "Foo Bar <foo@example.com>", { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" } ]},
-  q{[ 1, 2, 3 ]},
-  q{[ 1, 2, ]},
-  q{[
-    1,
-    2,
-  ]},
-  q{[
-    1,
-    2
-  ]},
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/boolean.t b/t/tokens/boolean.t
deleted file mode 100644 (file)
index 4a8fd43..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&Boolean)) $TOML }x;
-
-like 'true', $re, 'true';
-like 'false', $re, 'false';
-unlike 'invalid', $re, 'invalid';
-
-done_testing;
diff --git a/t/tokens/datetime.t b/t/tokens/datetime.t
deleted file mode 100644 (file)
index 413b4ac..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&DateTime)) $TOML }x;
-
-my @valid = (
-  '1979-05-27T07:32:00Z',
-  '1979-05-27T00:32:00-07:00',
-  '1979-05-27T00:32:00.999999-07:00',
-  '1979-05-27 07:32:00Z',
-  '1979-05-27T07:32:00',
-  '1979-05-27T00:32:00.999999',
-  '1979-05-27',
-  '07:32:00',
-  '00:32:00.999999',
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/float.t b/t/tokens/float.t
deleted file mode 100644 (file)
index 79e4ed0..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&Float)) $TOML }x;
-
-my @valid = qw(
-  0.01
-  +1.0
-  3.1415
-  -0.01
-  5e+22
-  1e06
-  -2E-2
-  6.626e-34
-  224_617.445_991_228
-  inf
-  +inf
-  -inf
-  nan
-  +nan
-  -nan
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/inline-table.t b/t/tokens/inline-table.t
deleted file mode 100644 (file)
index 3672343..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&InlineTable)) $TOML }x;
-
-my @valid = (
-  q|{ first = "Tom", last = "Preston-Werner" }|,
-  q|{ x = 1, y = 2 }|,
-  q|{ type.name = "pug" }|,
-  q|{ x = 1 }|,
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/integer.t b/t/tokens/integer.t
deleted file mode 100644 (file)
index efde783..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&Integer)) $TOML }x;
-
-my @valid = qw(
-  +99
-  42
-  0
-  -17
-  1_000
-  5_349_221
-  1_2_3_4_5
-  0xDEADBEEF
-  0xdeadbeef
-  0xdead_beef
-  0o01234567
-  0o755
-  0b110101101
-);
-
-like($_, $re, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/key-value-pair.t b/t/tokens/key-value-pair.t
deleted file mode 100644 (file)
index 9ea5a2b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&KeyValuePair)) $TOML }x;
-
-my @valid = (
-  q{foo= "bar"},
-  q{foo ="bar"},
-  q{foo="bar"},
-  q{foo = "bar"},
-  q{foo = 1234},
-  q{foo = 12.34},
-  q{foo = true},
-  q{foo = [1,2,3]},
-  q{foo = [1, 2, 3]},
-  q{foo = [ 1, 2, 3 ]},
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/key.t b/t/tokens/key.t
deleted file mode 100644 (file)
index f0ec3a9..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ ((?&Key)) $TOML }x;
-
-my @valid = qw(
-  key
-  bare_key
-  bare-key
-  1234
-  "127.0.0.1"
-  "character encoding"
-  "ʎǝʞ"
-  'key2'
-  'quoted "value"'
-  physical.color
-  physical.shape
-  site."google.com"
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;
diff --git a/t/tokens/string.t b/t/tokens/string.t
deleted file mode 100644 (file)
index f9985f3..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-sub test_simple_matches {
-  my ($re, @tests) = @_;
-  for (@tests) {
-    my ($toml, $expected, $label) = @$_;
-    my ($match) = $toml =~ $re;
-    is $match, $expected, $label;
-  }
-}
-
-subtest 'string group' => sub{
-  my $re = qr{ ((?&String)) $TOML }x;
-
-  test_simple_matches($re,
-    [q{"A"}, q{"A"}, 'basic string'],
-    [q{'A'}, q{'A'}, 'string literal'],
-    [q{"""A"""}, q{"""A"""}, 'multi-line string'],
-    [q{'''A'''}, q{'''A'''}, 'multi-line string literal'],
-  );
-};
-
-subtest 'escaped characters' => sub{
-  my $re = qr{
-    ((?&EscapeChar))
-    $TOML
-  }x;
-
-  test_simple_matches($re,
-    ['\\\\', '\\\\', 'slash'],
-    ['\\b', '\\b', 'backspace'],
-    ['\\t', '\\t', 'tab'],
-    ['\\n', '\\n', 'line feed'],
-    ['\\f', '\\f', 'form feed'],
-    ['\\r', '\\r', 'carriage return'],
-    ['\\"', '\\"', 'quote'],
-    ['\\\\', '\\\\', 'backslash'],
-    ['\\u1234', '\\u1234', 'unicode (4 bytes)'],
-    ['\\U12345678', '\\U12345678', 'unicode (8 bytes)'],
-    ['\\x', undef, 'invalid'],
-  );
-};
-
-subtest 'string literals' => sub{
-  my $re = qr{
-    ((?&StringLiteral))
-    $TOML
-  }x;
-
-  test_simple_matches($re,
-    [q{'abc'}, q{'abc'}, 'single-quoted'],
-    [q{''}, q{''}, 'empty single-quoted'],
-  );
-};
-
-subtest 'basic strings' => sub{
-  my $re = qr{
-    ((?&BasicString))
-    $TOML
-  }x;
-
-  test_simple_matches($re,
-    ['""', '""', "empty string"],
-    ['"abc"', '"abc"', 'simple'],
-    ['"\\tfoo"', '"\\tfoo"', 'escaped chars'],
-    ['1234', undef, 'invalid'],
-  );
-};
-
-subtest 'multi-line strings' => sub{
-  my $re = qr{
-    ((?&MultiLineString))
-    $TOML
-  }x;
-
-  test_simple_matches($re,
-    [ qq{"""\nabc"""}, qq{"""\nabc"""}, 'simple' ],
-    [ qq{""" " """}, q{""" " """}, 'containing 1 quote' ],
-    [ qq{""" "" """}, q{""" "" """}, 'containing 2 quotes' ],
-    [ qq{"""a\n"b"\nc"""}, qq{"""a\n"b"\nc"""}, 'individual quotes within ml string' ],
-    [ qq{"""foo"""bar"""}, qq{"""foo"""}, 'invalid: triple-quotes appear within ml string' ],
-  );
-};
-
-subtest 'multi-line string literals' => sub{
-  my $re = qr{ ((?&MultiLineStringLiteral)) $TOML }x;
-
-  test_simple_matches($re,
-    [ qq{'''\nabc'''}, qq{'''\nabc'''}, 'simple' ],
-    [ qq{''' ' '''}, q{''' ' '''}, 'containing 1 single tick' ],
-    [ qq{''' '' '''}, q{''' '' '''}, 'containing 2 single ticks' ],
-    [ qq{'''foo'''bar'''}, qq{'''foo'''}, 'invalid: triple-quotes appear within ml string' ],
-  );
-};
-
-done_testing;
diff --git a/t/tokens/table.t b/t/tokens/table.t
deleted file mode 100644 (file)
index 32d4ba4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-use Test2::V0;
-use TOML::Tiny::Grammar;
-
-my $re = qr{ (?&Table) $TOML }x;
-
-my @valid = (
-  qq{[foo]\n},
-
-  qq{[foo]
-bar = 1234},
-
-  qq{[foo]
-bar = 1234
-baz = 5678},
-
-  qq{[foo]
-bar = 1234
-[baz]
-bat = 5678},
-);
-
-ok($_ =~ /$re/, $_) for @valid;
-
-done_testing;