1 USING: assocs calendar multiline present toml tools.test ;
7 { "title" "TOML Example" }
11 { "name" "Tom Preston-Werner" }
12 { "organization" "GitHub" }
15 "GitHub Cofounder & CEO\nLikes tater tots and beer."
31 { "server" "192.168.1.1" }
32 { "ports" { 8001 8001 8002 } }
33 { "connection_max" 5000 }
60 { "data" { { "gamma" "delta" } { 1 2 } } }
61 { "hosts" { "alpha" "omega" } }
82 # This is a TOML document. Boom.
84 title = "TOML Example"
87 name = "Tom Preston-Werner"
88 organization = "GitHub"
89 bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
90 dob = 1979-05-27T07:32:00Z # First class dates? Why not?
93 server = "192.168.1.1"
94 ports = [ 8001, 8001, 8002 ]
100 # You can indent as you please. Tabs or spaces. TOML don't care.
108 country = "中国" # This should be parsed as UTF-8
111 data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
113 # Line breaks are OK when inside arrays
136 { "temp_targets" H{ { "case" 72.0 } } } }
141 temp_targets = { case = 72.0 }" toml>
145 H{ { "foo" H{ { "qux" 456 } { "bar" H{ { "baz" 123 } } } } } }
155 ! TESTS FROM 1.0.0 SPEC
159 H{ { "key" "value" } { "another" "# This is not a comment" } }
161 [=[ # This is a full-line comment
162 key = "value" # This is a comment at the end of a line
163 another = "# This is not a comment"]=] toml>
168 [ [=[ key = # INVALID]=] toml> ] must-fail
170 [ [=[ key = 1234abcd ]=] toml> ] must-fail
172 [ [=[ first = "Tom" last = "Preston-Werner" # INVALID]=] toml> ] must-fail
178 { "character encoding" "value" }
179 { "quoted \"value\"" "value" }
182 { "127.0.0.1" "value" }
186 "127.0.0.1" = "value"
187 "character encoding" = "value"
190 'quoted "value"' = "value"
194 [ [=[ = "no key name" # INVALID]=] toml> ] must-fail
195 { H{ { "" "blank" } } } [ [=[ "" = "blank" # VALID but discouraged]=] toml> ] unit-test
196 { H{ { "" "blank" } } } [ [=[ '' = "blank" # VALID but discouraged]=] toml> ] unit-test
200 { "physical" H{ { "color" "orange" } { "shape" "round" } } }
202 { "site" H{ { "google.com" t } } }
207 physical.color = "orange"
208 physical.shape = "round"
209 site."google.com" = true
218 { "flavor" "banana" }
224 fruit.name = "banana" # this is best practice
225 fruit. color = "yellow" # same as fruit.color
226 fruit . flavor = "banana" # same as fruit.flavor]=] toml>
233 ]=] toml> ] [ duplicate-key? ] must-fail-with
235 [ [=[ # THE FOLLOWING IS INVALID
237 # This defines the value of fruit.apple to be an integer.
240 # But then this treats fruit.apple like it's a table.
241 # You can't turn an integer into a table.
242 fruit.apple.smooth = true]=] toml> ] must-fail
244 { H{ { "3" H{ { "14159" "pi" } } } } } [
245 [=[ 3.14159 = "pi" ]=] toml>
254 "I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF."
258 [=[ str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF." ]=]
262 { H{ { "str1" "Roses are red\nViolets are blue" } } } [
265 Violets are blue"""]=] toml>
270 { "str1" "The quick brown fox jumps over the lazy dog." }
271 { "str2" "The quick brown fox jumps over the lazy dog." }
272 { "str3" "The quick brown fox jumps over the lazy dog." }
276 # The following strings are byte-for-byte equivalent:
277 str1 = "The quick brown fox jumps over the lazy dog."
296 { "regex" "<\\i\\c*\\s*>" }
297 { "quoted" "Tom \"Dubs\" Preston-Werner" }
298 { "winpath2" "\\\\ServerX\\admin$\\system32\\" }
299 { "winpath" "C:\\Users\\nodejs\\templates" }
302 [=[ # What you see is what you get.
303 winpath = 'C:\Users\nodejs\templates'
304 winpath2 = '\\ServerX\admin$\system32\'
305 quoted = 'Tom "Dubs" Preston-Werner'
306 regex = '<\i\c*\s*>' ]=] toml>
321 { "hex1" 0xdeadbeef }
322 { "hex2" 0xdeadbeef }
323 { "hex3" 0xdeadbeef }
324 { "oct1" 0o01234567 }
326 { "bin1" 0b11010110 }
336 int7 = 53_49_221 # Indian number system grouping
337 int8 = 1_2_3_4_5 # VALID but discouraged
339 # hexadecimal with prefix `0x`
344 # octal with prefix `0o`
346 oct2 = 0o755 # useful for Unix file permissions
348 # binary with prefix `0b`
353 [ [=[ key = +0o99 ]=] toml> ] must-fail
363 { "flt5" "1000000.0" }
365 { "flt7" "6.626e-34" }
366 { "flt8" "224617.445991228" }
389 flt8 = 224_617.445_991_228
392 sf1 = inf # positive infinity
393 sf2 = +inf # positive infinity
394 sf3 = -inf # negative infinity
397 sf4 = nan # actual sNaN/qNaN encoding is implementation-specific
398 sf5 = +nan # same as `nan`
399 sf6 = -nan # valid, actual encoding is implementation-specific
400 ]=] toml> [ present ] assoc-map
403 [ [=[ invalid_float_1 = .7]=] toml> ] must-fail
404 [ [=[ invalid_float_2 = 7.]=] toml> ] must-fail
405 [ [=[ invalid_float_2 = 3.e+20]=] toml> ] must-fail
409 { H{ { "bool1" t } { "bool2" f } } } [
411 bool2 = false]=] toml>
445 { gmt-offset T{ duration { hour -7 } } }
455 { second 999999/1000000 }
456 { gmt-offset T{ duration { hour -7 } } }
462 odt1 = 1979-05-27T07:32:00Z
463 odt2 = 1979-05-27T00:32:00-07:00
464 odt3 = 1979-05-27T00:32:00.999999-07:00
465 odt4 = 1979-05-27 07:32:00Z
490 { second 999999/1000000 }
496 ldt1 = 1979-05-27T07:32:00
497 ldt2 = 1979-05-27T00:32:00.999999
503 { H{ { "ld1" "1979-05-27" } } } [
511 { H{ { "lt2" "00:32:00.999999" } { "lt1" "07:32:00" } } } [
514 lt2 = 00:32:00.999999
522 { "integers" { 1 2 3 } }
523 { "colors" { "red" "yellow" "green" } }
524 { "nested_arrays_of_ints" { { 1 2 } { 3 4 5 } } }
525 { "nested_mixed_array" { { 1 2 } { "a" "b" "c" } } }
526 { "string_array" { "all" "strings" "are the same" "type" } }
527 { "numbers" { 0.1 0.2 0.5 1 2 5 } }
531 "Foo Bar <foo@example.com>"
534 { "email" "bazqux@example.com" }
535 { "url" "https://example.com/bazqux" }
542 integers = [ 1, 2, 3 ]
543 colors = [ "red", "yellow", "green" ]
544 nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
545 nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ]
546 string_array = [ "all", 'strings', """are the same""", '''type''' ]
548 # Mixed-type arrays are allowed
549 numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
551 "Foo Bar <foo@example.com>",
552 { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
559 { "integers2" { 1 2 3 } }
560 { "integers3" { 1 2 } }
576 H{ { "j" H{ { "ʞ" H{ { "l" H{ { "key1" t } } } } } } } }
590 H{ { "first" "Tom" } { "last" "Preston-Werner" } }
592 { "point" H{ { "x" 1 } { "y" 2 } } }
593 { "animal" H{ { "type" H{ { "name" "pug" } } } } }
597 name = { first = "Tom", last = "Preston-Werner" }
598 point = { x = 1, y = 2 }
599 animal = { type.name = "pug" }]=] toml>
607 H{ { "x" 1 } { "y" 2 } { "z" 3 } }
608 H{ { "x" 7 } { "y" 8 } { "z" 9 } }
609 H{ { "x" 2 } { "y" 4 } { "z" 8 } }
614 [=[ points = [ { x = 1, y = 2, z = 3 },
615 { x = 7, y = 8, z = 9 },
616 { x = 2, y = 4, z = 8 } ] ]=] toml>
619 { H{ { "a" { } } } } [ "a=[]" toml> ] unit-test
620 { H{ { "a" { 1 } } } } [ "a=[1]" toml> ] unit-test
621 { H{ { "a" { 1 2 3 } } } } [ "a=[1,2,3]" toml> ] unit-test
622 { H{ { "a" { 1 2 3 } } } } [ "a=[,1,,,,2,,3,,]" toml> ] unit-test
623 { H{ { "a" { 1 2 3 } } } } [ "a=[ # this\n,1,, # is\n,,2, #a\n,3,, # comment \n]" toml> ] unit-test
627 ! Clarify Unicode and UTF-8 references.
628 ! Relax comment parsing; most control characters are again permitted.
629 ! Allow newline after key/values in inline tables.
630 ! Allow trailing comma in inline tables.
631 ! Clarify where and how dotted keys define tables.
632 ! Add new \e shorthand for the escape character.
633 ! Add \x00 notation to basic strings.
634 ! Seconds in Date-Time and Time values are now optional.
635 ! Allow non-English scripts in unquoted (bare) keys
636 ! Clarify newline normalization in multi-line literal strings.