...

Source file src/github.com/pelletier/go-toml/toml_testgen_test.go

Documentation: github.com/pelletier/go-toml

     1  // Generated by tomltestgen for toml-test ref 39e37e6 on 2019-03-19T23:58:45-07:00
     2  package toml
     3  
     4  import (
     5  	"testing"
     6  )
     7  
     8  func TestInvalidDatetimeMalformedNoLeads(t *testing.T) {
     9  	input := `no-leads = 1987-7-05T17:45:00Z`
    10  	testgenInvalid(t, input)
    11  }
    12  
    13  func TestInvalidDatetimeMalformedNoSecs(t *testing.T) {
    14  	input := `no-secs = 1987-07-05T17:45Z`
    15  	testgenInvalid(t, input)
    16  }
    17  
    18  func TestInvalidDatetimeMalformedNoT(t *testing.T) {
    19  	input := `no-t = 1987-07-0517:45:00Z`
    20  	testgenInvalid(t, input)
    21  }
    22  
    23  func TestInvalidDatetimeMalformedWithMilli(t *testing.T) {
    24  	input := `with-milli = 1987-07-5T17:45:00.12Z`
    25  	testgenInvalid(t, input)
    26  }
    27  
    28  func TestInvalidDuplicateKeyTable(t *testing.T) {
    29  	input := `[fruit]
    30  type = "apple"
    31  
    32  [fruit.type]
    33  apple = "yes"`
    34  	testgenInvalid(t, input)
    35  }
    36  
    37  func TestInvalidDuplicateKeys(t *testing.T) {
    38  	input := `dupe = false
    39  dupe = true`
    40  	testgenInvalid(t, input)
    41  }
    42  
    43  func TestInvalidDuplicateTables(t *testing.T) {
    44  	input := `[a]
    45  [a]`
    46  	testgenInvalid(t, input)
    47  }
    48  
    49  func TestInvalidEmptyImplicitTable(t *testing.T) {
    50  	input := `[naughty..naughty]`
    51  	testgenInvalid(t, input)
    52  }
    53  
    54  func TestInvalidEmptyTable(t *testing.T) {
    55  	input := `[]`
    56  	testgenInvalid(t, input)
    57  }
    58  
    59  func TestInvalidFloatNoLeadingZero(t *testing.T) {
    60  	input := `answer = .12345
    61  neganswer = -.12345`
    62  	testgenInvalid(t, input)
    63  }
    64  
    65  func TestInvalidFloatNoTrailingDigits(t *testing.T) {
    66  	input := `answer = 1.
    67  neganswer = -1.`
    68  	testgenInvalid(t, input)
    69  }
    70  
    71  func TestInvalidKeyEmpty(t *testing.T) {
    72  	input := ` = 1`
    73  	testgenInvalid(t, input)
    74  }
    75  
    76  func TestInvalidKeyHash(t *testing.T) {
    77  	input := `a# = 1`
    78  	testgenInvalid(t, input)
    79  }
    80  
    81  func TestInvalidKeyNewline(t *testing.T) {
    82  	input := `a
    83  = 1`
    84  	testgenInvalid(t, input)
    85  }
    86  
    87  func TestInvalidKeyOpenBracket(t *testing.T) {
    88  	input := `[abc = 1`
    89  	testgenInvalid(t, input)
    90  }
    91  
    92  func TestInvalidKeySingleOpenBracket(t *testing.T) {
    93  	input := `[`
    94  	testgenInvalid(t, input)
    95  }
    96  
    97  func TestInvalidKeySpace(t *testing.T) {
    98  	input := `a b = 1`
    99  	testgenInvalid(t, input)
   100  }
   101  
   102  func TestInvalidKeyStartBracket(t *testing.T) {
   103  	input := `[a]
   104  [xyz = 5
   105  [b]`
   106  	testgenInvalid(t, input)
   107  }
   108  
   109  func TestInvalidKeyTwoEquals(t *testing.T) {
   110  	input := `key= = 1`
   111  	testgenInvalid(t, input)
   112  }
   113  
   114  func TestInvalidStringBadByteEscape(t *testing.T) {
   115  	input := `naughty = "\xAg"`
   116  	testgenInvalid(t, input)
   117  }
   118  
   119  func TestInvalidStringBadEscape(t *testing.T) {
   120  	input := `invalid-escape = "This string has a bad \a escape character."`
   121  	testgenInvalid(t, input)
   122  }
   123  
   124  func TestInvalidStringByteEscapes(t *testing.T) {
   125  	input := `answer = "\x33"`
   126  	testgenInvalid(t, input)
   127  }
   128  
   129  func TestInvalidStringNoClose(t *testing.T) {
   130  	input := `no-ending-quote = "One time, at band camp`
   131  	testgenInvalid(t, input)
   132  }
   133  
   134  func TestInvalidTableArrayImplicit(t *testing.T) {
   135  	input := "# This test is a bit tricky. It should fail because the first use of\n" +
   136  		"# `[[albums.songs]]` without first declaring `albums` implies that `albums`\n" +
   137  		"# must be a table. The alternative would be quite weird. Namely, it wouldn't\n" +
   138  		"# comply with the TOML spec: \"Each double-bracketed sub-table will belong to \n" +
   139  		"# the most *recently* defined table element *above* it.\"\n" +
   140  		"#\n" +
   141  		"# This is in contrast to the *valid* test, table-array-implicit where\n" +
   142  		"# `[[albums.songs]]` works by itself, so long as `[[albums]]` isn't declared\n" +
   143  		"# later. (Although, `[albums]` could be.)\n" +
   144  		"[[albums.songs]]\n" +
   145  		"name = \"Glory Days\"\n" +
   146  		"\n" +
   147  		"[[albums]]\n" +
   148  		"name = \"Born in the USA\"\n"
   149  	testgenInvalid(t, input)
   150  }
   151  
   152  func TestInvalidTableArrayMalformedBracket(t *testing.T) {
   153  	input := `[[albums]
   154  name = "Born to Run"`
   155  	testgenInvalid(t, input)
   156  }
   157  
   158  func TestInvalidTableArrayMalformedEmpty(t *testing.T) {
   159  	input := `[[]]
   160  name = "Born to Run"`
   161  	testgenInvalid(t, input)
   162  }
   163  
   164  func TestInvalidTableEmpty(t *testing.T) {
   165  	input := `[]`
   166  	testgenInvalid(t, input)
   167  }
   168  
   169  func TestInvalidTableNestedBracketsClose(t *testing.T) {
   170  	input := `[a]b]
   171  zyx = 42`
   172  	testgenInvalid(t, input)
   173  }
   174  
   175  func TestInvalidTableNestedBracketsOpen(t *testing.T) {
   176  	input := `[a[b]
   177  zyx = 42`
   178  	testgenInvalid(t, input)
   179  }
   180  
   181  func TestInvalidTableWhitespace(t *testing.T) {
   182  	input := `[invalid key]`
   183  	testgenInvalid(t, input)
   184  }
   185  
   186  func TestInvalidTableWithPound(t *testing.T) {
   187  	input := `[key#group]
   188  answer = 42`
   189  	testgenInvalid(t, input)
   190  }
   191  
   192  func TestInvalidTextAfterArrayEntries(t *testing.T) {
   193  	input := `array = [
   194    "Is there life after an array separator?", No
   195    "Entry"
   196  ]`
   197  	testgenInvalid(t, input)
   198  }
   199  
   200  func TestInvalidTextAfterInteger(t *testing.T) {
   201  	input := `answer = 42 the ultimate answer?`
   202  	testgenInvalid(t, input)
   203  }
   204  
   205  func TestInvalidTextAfterString(t *testing.T) {
   206  	input := `string = "Is there life after strings?" No.`
   207  	testgenInvalid(t, input)
   208  }
   209  
   210  func TestInvalidTextAfterTable(t *testing.T) {
   211  	input := `[error] this shouldn't be here`
   212  	testgenInvalid(t, input)
   213  }
   214  
   215  func TestInvalidTextBeforeArraySeparator(t *testing.T) {
   216  	input := `array = [
   217    "Is there life before an array separator?" No,
   218    "Entry"
   219  ]`
   220  	testgenInvalid(t, input)
   221  }
   222  
   223  func TestInvalidTextInArray(t *testing.T) {
   224  	input := `array = [
   225    "Entry 1",
   226    I don't belong,
   227    "Entry 2",
   228  ]`
   229  	testgenInvalid(t, input)
   230  }
   231  
   232  func TestValidArrayEmpty(t *testing.T) {
   233  	input := `thevoid = [[[[[]]]]]`
   234  	jsonRef := `{
   235      "thevoid": { "type": "array", "value": [
   236          {"type": "array", "value": [
   237              {"type": "array", "value": [
   238                  {"type": "array", "value": [
   239                      {"type": "array", "value": []}
   240                  ]}
   241              ]}
   242          ]}
   243      ]}
   244  }`
   245  	testgenValid(t, input, jsonRef)
   246  }
   247  
   248  func TestValidArrayNospaces(t *testing.T) {
   249  	input := `ints = [1,2,3]`
   250  	jsonRef := `{
   251      "ints": {
   252          "type": "array",
   253          "value": [
   254              {"type": "integer", "value": "1"},
   255              {"type": "integer", "value": "2"},
   256              {"type": "integer", "value": "3"}
   257          ]
   258      }
   259  }`
   260  	testgenValid(t, input, jsonRef)
   261  }
   262  
   263  func TestValidArraysHetergeneous(t *testing.T) {
   264  	input := `mixed = [[1, 2], ["a", "b"], [1.1, 2.1]]`
   265  	jsonRef := `{
   266      "mixed": {
   267          "type": "array",
   268          "value": [
   269              {"type": "array", "value": [
   270                  {"type": "integer", "value": "1"},
   271                  {"type": "integer", "value": "2"}
   272              ]},
   273              {"type": "array", "value": [
   274                  {"type": "string", "value": "a"},
   275                  {"type": "string", "value": "b"}
   276              ]},
   277              {"type": "array", "value": [
   278                  {"type": "float", "value": "1.1"},
   279                  {"type": "float", "value": "2.1"}
   280              ]}
   281          ]
   282      }
   283  }`
   284  	testgenValid(t, input, jsonRef)
   285  }
   286  
   287  func TestValidArraysNested(t *testing.T) {
   288  	input := `nest = [["a"], ["b"]]`
   289  	jsonRef := `{
   290      "nest": {
   291          "type": "array",
   292          "value": [
   293              {"type": "array", "value": [
   294                  {"type": "string", "value": "a"}
   295              ]},
   296              {"type": "array", "value": [
   297                  {"type": "string", "value": "b"}
   298              ]}
   299          ]
   300      }
   301  }`
   302  	testgenValid(t, input, jsonRef)
   303  }
   304  
   305  func TestValidArrays(t *testing.T) {
   306  	input := `ints = [1, 2, 3]
   307  floats = [1.1, 2.1, 3.1]
   308  strings = ["a", "b", "c"]
   309  dates = [
   310    1987-07-05T17:45:00Z,
   311    1979-05-27T07:32:00Z,
   312    2006-06-01T11:00:00Z,
   313  ]`
   314  	jsonRef := `{
   315      "ints": {
   316          "type": "array",
   317          "value": [
   318              {"type": "integer", "value": "1"},
   319              {"type": "integer", "value": "2"},
   320              {"type": "integer", "value": "3"}
   321          ]
   322      },
   323      "floats": {
   324          "type": "array",
   325          "value": [
   326              {"type": "float", "value": "1.1"},
   327              {"type": "float", "value": "2.1"},
   328              {"type": "float", "value": "3.1"}
   329          ]
   330      },
   331      "strings": {
   332          "type": "array",
   333          "value": [
   334              {"type": "string", "value": "a"},
   335              {"type": "string", "value": "b"},
   336              {"type": "string", "value": "c"}
   337          ]
   338      },
   339      "dates": {
   340          "type": "array",
   341          "value": [
   342              {"type": "datetime", "value": "1987-07-05T17:45:00Z"},
   343              {"type": "datetime", "value": "1979-05-27T07:32:00Z"},
   344              {"type": "datetime", "value": "2006-06-01T11:00:00Z"}
   345          ]
   346      }
   347  }`
   348  	testgenValid(t, input, jsonRef)
   349  }
   350  
   351  func TestValidBool(t *testing.T) {
   352  	input := `t = true
   353  f = false`
   354  	jsonRef := `{
   355      "f": {"type": "bool", "value": "false"},
   356      "t": {"type": "bool", "value": "true"}
   357  }`
   358  	testgenValid(t, input, jsonRef)
   359  }
   360  
   361  func TestValidCommentsEverywhere(t *testing.T) {
   362  	input := `# Top comment.
   363    # Top comment.
   364  # Top comment.
   365  
   366  # [no-extraneous-groups-please]
   367  
   368  [group] # Comment
   369  answer = 42 # Comment
   370  # no-extraneous-keys-please = 999
   371  # Inbetween comment.
   372  more = [ # Comment
   373    # What about multiple # comments?
   374    # Can you handle it?
   375    #
   376            # Evil.
   377  # Evil.
   378    42, 42, # Comments within arrays are fun.
   379    # What about multiple # comments?
   380    # Can you handle it?
   381    #
   382            # Evil.
   383  # Evil.
   384  # ] Did I fool you?
   385  ] # Hopefully not.`
   386  	jsonRef := `{
   387      "group": {
   388          "answer": {"type": "integer", "value": "42"},
   389          "more": {
   390              "type": "array",
   391              "value": [
   392                  {"type": "integer", "value": "42"},
   393                  {"type": "integer", "value": "42"}
   394              ]
   395          }
   396      }
   397  }`
   398  	testgenValid(t, input, jsonRef)
   399  }
   400  
   401  func TestValidDatetime(t *testing.T) {
   402  	input := `bestdayever = 1987-07-05T17:45:00Z`
   403  	jsonRef := `{
   404      "bestdayever": {"type": "datetime", "value": "1987-07-05T17:45:00Z"}
   405  }`
   406  	testgenValid(t, input, jsonRef)
   407  }
   408  
   409  func TestValidEmpty(t *testing.T) {
   410  	input := ``
   411  	jsonRef := `{}`
   412  	testgenValid(t, input, jsonRef)
   413  }
   414  
   415  func TestValidExample(t *testing.T) {
   416  	input := `best-day-ever = 1987-07-05T17:45:00Z
   417  
   418  [numtheory]
   419  boring = false
   420  perfection = [6, 28, 496]`
   421  	jsonRef := `{
   422    "best-day-ever": {"type": "datetime", "value": "1987-07-05T17:45:00Z"},
   423    "numtheory": {
   424      "boring": {"type": "bool", "value": "false"},
   425      "perfection": {
   426        "type": "array",
   427        "value": [
   428          {"type": "integer", "value": "6"},
   429          {"type": "integer", "value": "28"},
   430          {"type": "integer", "value": "496"}
   431        ]
   432      }
   433    }
   434  }`
   435  	testgenValid(t, input, jsonRef)
   436  }
   437  
   438  func TestValidFloat(t *testing.T) {
   439  	input := `pi = 3.14
   440  negpi = -3.14`
   441  	jsonRef := `{
   442      "pi": {"type": "float", "value": "3.14"},
   443      "negpi": {"type": "float", "value": "-3.14"}
   444  }`
   445  	testgenValid(t, input, jsonRef)
   446  }
   447  
   448  func TestValidImplicitAndExplicitAfter(t *testing.T) {
   449  	input := `[a.b.c]
   450  answer = 42
   451  
   452  [a]
   453  better = 43`
   454  	jsonRef := `{
   455      "a": {
   456          "better": {"type": "integer", "value": "43"},
   457          "b": {
   458              "c": {
   459                  "answer": {"type": "integer", "value": "42"}
   460              }
   461          }
   462      }
   463  }`
   464  	testgenValid(t, input, jsonRef)
   465  }
   466  
   467  func TestValidImplicitAndExplicitBefore(t *testing.T) {
   468  	input := `[a]
   469  better = 43
   470  
   471  [a.b.c]
   472  answer = 42`
   473  	jsonRef := `{
   474      "a": {
   475          "better": {"type": "integer", "value": "43"},
   476          "b": {
   477              "c": {
   478                  "answer": {"type": "integer", "value": "42"}
   479              }
   480          }
   481      }
   482  }`
   483  	testgenValid(t, input, jsonRef)
   484  }
   485  
   486  func TestValidImplicitGroups(t *testing.T) {
   487  	input := `[a.b.c]
   488  answer = 42`
   489  	jsonRef := `{
   490      "a": {
   491          "b": {
   492              "c": {
   493                  "answer": {"type": "integer", "value": "42"}
   494              }
   495          }
   496      }
   497  }`
   498  	testgenValid(t, input, jsonRef)
   499  }
   500  
   501  func TestValidInteger(t *testing.T) {
   502  	input := `answer = 42
   503  neganswer = -42`
   504  	jsonRef := `{
   505      "answer": {"type": "integer", "value": "42"},
   506      "neganswer": {"type": "integer", "value": "-42"}
   507  }`
   508  	testgenValid(t, input, jsonRef)
   509  }
   510  
   511  func TestValidKeyEqualsNospace(t *testing.T) {
   512  	input := `answer=42`
   513  	jsonRef := `{
   514      "answer": {"type": "integer", "value": "42"}
   515  }`
   516  	testgenValid(t, input, jsonRef)
   517  }
   518  
   519  func TestValidKeySpace(t *testing.T) {
   520  	input := `"a b" = 1`
   521  	jsonRef := `{
   522      "a b": {"type": "integer", "value": "1"}
   523  }`
   524  	testgenValid(t, input, jsonRef)
   525  }
   526  
   527  func TestValidKeySpecialChars(t *testing.T) {
   528  	input := "\"~!@$^&*()_+-`1234567890[]|/?><.,;:'\" = 1\n"
   529  	jsonRef := "{\n" +
   530  		"    \"~!@$^&*()_+-`1234567890[]|/?><.,;:'\": {\n" +
   531  		"        \"type\": \"integer\", \"value\": \"1\"\n" +
   532  		"    }\n" +
   533  		"}\n"
   534  	testgenValid(t, input, jsonRef)
   535  }
   536  
   537  func TestValidLongFloat(t *testing.T) {
   538  	input := `longpi = 3.141592653589793
   539  neglongpi = -3.141592653589793`
   540  	jsonRef := `{
   541      "longpi": {"type": "float", "value": "3.141592653589793"},
   542      "neglongpi": {"type": "float", "value": "-3.141592653589793"}
   543  }`
   544  	testgenValid(t, input, jsonRef)
   545  }
   546  
   547  func TestValidLongInteger(t *testing.T) {
   548  	input := `answer = 9223372036854775807
   549  neganswer = -9223372036854775808`
   550  	jsonRef := `{
   551      "answer": {"type": "integer", "value": "9223372036854775807"},
   552      "neganswer": {"type": "integer", "value": "-9223372036854775808"}
   553  }`
   554  	testgenValid(t, input, jsonRef)
   555  }
   556  
   557  func TestValidMultilineString(t *testing.T) {
   558  	input := `multiline_empty_one = """"""
   559  multiline_empty_two = """
   560  """
   561  multiline_empty_three = """\
   562      """
   563  multiline_empty_four = """\
   564     \
   565     \
   566     """
   567  
   568  equivalent_one = "The quick brown fox jumps over the lazy dog."
   569  equivalent_two = """
   570  The quick brown \
   571  
   572  
   573    fox jumps over \
   574      the lazy dog."""
   575  
   576  equivalent_three = """\
   577         The quick brown \
   578         fox jumps over \
   579         the lazy dog.\
   580         """`
   581  	jsonRef := `{
   582      "multiline_empty_one": {
   583          "type": "string",
   584          "value": ""
   585      },
   586      "multiline_empty_two": {
   587          "type": "string",
   588          "value": ""
   589      },
   590      "multiline_empty_three": {
   591          "type": "string",
   592          "value": ""
   593      },
   594      "multiline_empty_four": {
   595          "type": "string",
   596          "value": ""
   597      },
   598      "equivalent_one": {
   599          "type": "string",
   600          "value": "The quick brown fox jumps over the lazy dog."
   601      },
   602      "equivalent_two": {
   603          "type": "string",
   604          "value": "The quick brown fox jumps over the lazy dog."
   605      },
   606      "equivalent_three": {
   607          "type": "string",
   608          "value": "The quick brown fox jumps over the lazy dog."
   609      }
   610  }`
   611  	testgenValid(t, input, jsonRef)
   612  }
   613  
   614  func TestValidRawMultilineString(t *testing.T) {
   615  	input := `oneline = '''This string has a ' quote character.'''
   616  firstnl = '''
   617  This string has a ' quote character.'''
   618  multiline = '''
   619  This string
   620  has ' a quote character
   621  and more than
   622  one newline
   623  in it.'''`
   624  	jsonRef := `{
   625      "oneline": {
   626          "type": "string",
   627          "value": "This string has a ' quote character."
   628      },
   629      "firstnl": {
   630          "type": "string",
   631          "value": "This string has a ' quote character."
   632      },
   633      "multiline": {
   634          "type": "string",
   635          "value": "This string\nhas ' a quote character\nand more than\none newline\nin it."
   636      }
   637  }`
   638  	testgenValid(t, input, jsonRef)
   639  }
   640  
   641  func TestValidRawString(t *testing.T) {
   642  	input := `backspace = 'This string has a \b backspace character.'
   643  tab = 'This string has a \t tab character.'
   644  newline = 'This string has a \n new line character.'
   645  formfeed = 'This string has a \f form feed character.'
   646  carriage = 'This string has a \r carriage return character.'
   647  slash = 'This string has a \/ slash character.'
   648  backslash = 'This string has a \\ backslash character.'`
   649  	jsonRef := `{
   650      "backspace": {
   651          "type": "string",
   652          "value": "This string has a \\b backspace character."
   653      },
   654      "tab": {
   655          "type": "string",
   656          "value": "This string has a \\t tab character."
   657      },
   658      "newline": {
   659          "type": "string",
   660          "value": "This string has a \\n new line character."
   661      },
   662      "formfeed": {
   663          "type": "string",
   664          "value": "This string has a \\f form feed character."
   665      },
   666      "carriage": {
   667          "type": "string",
   668          "value": "This string has a \\r carriage return character."
   669      },
   670      "slash": {
   671          "type": "string",
   672          "value": "This string has a \\/ slash character."
   673      },
   674      "backslash": {
   675          "type": "string",
   676          "value": "This string has a \\\\ backslash character."
   677      }
   678  }`
   679  	testgenValid(t, input, jsonRef)
   680  }
   681  
   682  func TestValidStringEmpty(t *testing.T) {
   683  	input := `answer = ""`
   684  	jsonRef := `{
   685      "answer": {
   686          "type": "string",
   687          "value": ""
   688      }
   689  }`
   690  	testgenValid(t, input, jsonRef)
   691  }
   692  
   693  func TestValidStringEscapes(t *testing.T) {
   694  	input := `backspace = "This string has a \b backspace character."
   695  tab = "This string has a \t tab character."
   696  newline = "This string has a \n new line character."
   697  formfeed = "This string has a \f form feed character."
   698  carriage = "This string has a \r carriage return character."
   699  quote = "This string has a \" quote character."
   700  backslash = "This string has a \\ backslash character."
   701  notunicode1 = "This string does not have a unicode \\u escape."
   702  notunicode2 = "This string does not have a unicode \u005Cu escape."
   703  notunicode3 = "This string does not have a unicode \\u0075 escape."
   704  notunicode4 = "This string does not have a unicode \\\u0075 escape."`
   705  	jsonRef := `{
   706      "backspace": {
   707          "type": "string",
   708          "value": "This string has a \u0008 backspace character."
   709      },
   710      "tab": {
   711          "type": "string",
   712          "value": "This string has a \u0009 tab character."
   713      },
   714      "newline": {
   715          "type": "string",
   716          "value": "This string has a \u000A new line character."
   717      },
   718      "formfeed": {
   719          "type": "string",
   720          "value": "This string has a \u000C form feed character."
   721      },
   722      "carriage": {
   723          "type": "string",
   724          "value": "This string has a \u000D carriage return character."
   725      },
   726      "quote": {
   727          "type": "string",
   728          "value": "This string has a \u0022 quote character."
   729      },
   730      "backslash": {
   731          "type": "string",
   732          "value": "This string has a \u005C backslash character."
   733      },
   734      "notunicode1": {
   735          "type": "string",
   736          "value": "This string does not have a unicode \\u escape."
   737      },
   738      "notunicode2": {
   739          "type": "string",
   740          "value": "This string does not have a unicode \u005Cu escape."
   741      },
   742      "notunicode3": {
   743          "type": "string",
   744          "value": "This string does not have a unicode \\u0075 escape."
   745      },
   746      "notunicode4": {
   747          "type": "string",
   748          "value": "This string does not have a unicode \\\u0075 escape."
   749      }
   750  }`
   751  	testgenValid(t, input, jsonRef)
   752  }
   753  
   754  func TestValidStringSimple(t *testing.T) {
   755  	input := `answer = "You are not drinking enough whisky."`
   756  	jsonRef := `{
   757      "answer": {
   758          "type": "string",
   759          "value": "You are not drinking enough whisky."
   760      }
   761  }`
   762  	testgenValid(t, input, jsonRef)
   763  }
   764  
   765  func TestValidStringWithPound(t *testing.T) {
   766  	input := `pound = "We see no # comments here."
   767  poundcomment = "But there are # some comments here." # Did I # mess you up?`
   768  	jsonRef := `{
   769      "pound": {"type": "string", "value": "We see no # comments here."},
   770      "poundcomment": {
   771          "type": "string",
   772          "value": "But there are # some comments here."
   773      }
   774  }`
   775  	testgenValid(t, input, jsonRef)
   776  }
   777  
   778  func TestValidTableArrayImplicit(t *testing.T) {
   779  	input := `[[albums.songs]]
   780  name = "Glory Days"`
   781  	jsonRef := `{
   782      "albums": {
   783         "songs": [
   784             {"name": {"type": "string", "value": "Glory Days"}}
   785         ]
   786      }
   787  }`
   788  	testgenValid(t, input, jsonRef)
   789  }
   790  
   791  func TestValidTableArrayMany(t *testing.T) {
   792  	input := `[[people]]
   793  first_name = "Bruce"
   794  last_name = "Springsteen"
   795  
   796  [[people]]
   797  first_name = "Eric"
   798  last_name = "Clapton"
   799  
   800  [[people]]
   801  first_name = "Bob"
   802  last_name = "Seger"`
   803  	jsonRef := `{
   804      "people": [
   805          {
   806              "first_name": {"type": "string", "value": "Bruce"},
   807              "last_name": {"type": "string", "value": "Springsteen"}
   808          },
   809          {
   810              "first_name": {"type": "string", "value": "Eric"},
   811              "last_name": {"type": "string", "value": "Clapton"}
   812          },
   813          {
   814              "first_name": {"type": "string", "value": "Bob"},
   815              "last_name": {"type": "string", "value": "Seger"}
   816          }
   817      ]
   818  }`
   819  	testgenValid(t, input, jsonRef)
   820  }
   821  
   822  func TestValidTableArrayNest(t *testing.T) {
   823  	input := `[[albums]]
   824  name = "Born to Run"
   825  
   826    [[albums.songs]]
   827    name = "Jungleland"
   828  
   829    [[albums.songs]]
   830    name = "Meeting Across the River"
   831  
   832  [[albums]]
   833  name = "Born in the USA"
   834    
   835    [[albums.songs]]
   836    name = "Glory Days"
   837  
   838    [[albums.songs]]
   839    name = "Dancing in the Dark"`
   840  	jsonRef := `{
   841      "albums": [
   842          {
   843              "name": {"type": "string", "value": "Born to Run"},
   844              "songs": [
   845                  {"name": {"type": "string", "value": "Jungleland"}},
   846                  {"name": {"type": "string", "value": "Meeting Across the River"}}
   847              ]
   848          },
   849          {
   850              "name": {"type": "string", "value": "Born in the USA"},
   851              "songs": [
   852                  {"name": {"type": "string", "value": "Glory Days"}},
   853                  {"name": {"type": "string", "value": "Dancing in the Dark"}}
   854              ]
   855          }
   856      ]
   857  }`
   858  	testgenValid(t, input, jsonRef)
   859  }
   860  
   861  func TestValidTableArrayOne(t *testing.T) {
   862  	input := `[[people]]
   863  first_name = "Bruce"
   864  last_name = "Springsteen"`
   865  	jsonRef := `{
   866      "people": [
   867          {
   868              "first_name": {"type": "string", "value": "Bruce"},
   869              "last_name": {"type": "string", "value": "Springsteen"}
   870          }
   871      ]
   872  }`
   873  	testgenValid(t, input, jsonRef)
   874  }
   875  
   876  func TestValidTableEmpty(t *testing.T) {
   877  	input := `[a]`
   878  	jsonRef := `{
   879      "a": {}
   880  }`
   881  	testgenValid(t, input, jsonRef)
   882  }
   883  
   884  func TestValidTableSubEmpty(t *testing.T) {
   885  	input := `[a]
   886  [a.b]`
   887  	jsonRef := `{
   888      "a": { "b": {} }
   889  }`
   890  	testgenValid(t, input, jsonRef)
   891  }
   892  
   893  func TestValidTableWhitespace(t *testing.T) {
   894  	input := `["valid key"]`
   895  	jsonRef := `{
   896      "valid key": {}
   897  }`
   898  	testgenValid(t, input, jsonRef)
   899  }
   900  
   901  func TestValidTableWithPound(t *testing.T) {
   902  	input := `["key#group"]
   903  answer = 42`
   904  	jsonRef := `{
   905      "key#group": {
   906          "answer": {"type": "integer", "value": "42"}
   907      }
   908  }`
   909  	testgenValid(t, input, jsonRef)
   910  }
   911  
   912  func TestValidUnicodeEscape(t *testing.T) {
   913  	input := `answer4 = "\u03B4"
   914  answer8 = "\U000003B4"`
   915  	jsonRef := `{
   916      "answer4": {"type": "string", "value": "\u03B4"},
   917      "answer8": {"type": "string", "value": "\u03B4"}
   918  }`
   919  	testgenValid(t, input, jsonRef)
   920  }
   921  
   922  func TestValidUnicodeLiteral(t *testing.T) {
   923  	input := `answer = "δ"`
   924  	jsonRef := `{
   925      "answer": {"type": "string", "value": "δ"}
   926  }`
   927  	testgenValid(t, input, jsonRef)
   928  }
   929  

View as plain text