from std/data/toml import *;
from test/more import *;
let t := new TOML( pretty: false, canonical: true );
let encoded := t.encode( { title: "Example", owner: { name: "Tom Preston-Werner", dob: "1979-05-27" },
    db: { enabled: true, ports: [ 8000, 8001, 8002 ] } } );
like( encoded, /\[db\]\nenabled = true\nports = \[8000,8001,8002\]/, "encode nested table section" );
like( encoded, /\[owner\]\ndob = "1979-05-27"\nname = "Tom Preston-Werner"/, "encode canonical key order" );
let parsed := t.decode( "\n# comment\ntitle = \"Example\"\n[owner]\nname = \"Tom\"\nactive = true\nports = [8000, 8001]\n" );
is( parsed{title}, "Example", "decoded title" );
is( parsed{owner}{name}, "Tom", "decoded nested table" );
is( parsed{owner}{active}, true, "decoded bool" );
is( parsed{owner}{ports} [1], 8001, "decoded array values" );
ok( t.encode_binarystring( { title: "Example" } ) instanceof BinaryString, "encode_binarystring returns BinaryString" );
let parsed_binary := t.decode_binarystring( to_binary("title = \"café\"\n") );
is( parsed_binary{title}, "café", "decode_binarystring decodes UTF-8 TOML bytes" );
let setv := [ 3, 2, 1 ].to_Set();
let bagv := [ 3, 2, 1, 1 ].to_Bag();
let nested := {{
	foo: 1,
	foo: 2,
	bar: setv,
	baz: bagv,
}};
let simpler := {
	foo: 1,
	bar: [ 1, 2, 3 ],
	baz: [ 1, 1, 2, 3 ],
};
is( t.encode(nested), t.encode(simpler), "TOML encodes PairList, Set, and Bag as expected", );
done_testing();
