project created

This commit is contained in:
2025-11-09 23:47:51 +05:00
commit a5aff56fb1
20 changed files with 2909 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
[a]
aa = 1
[[a.b]]
bb = 2
[[a.b]]
cc = 3
[a.c]
dd = 4
[a.c.d]
ee = 5
[[a.c.d.e]]
ff = 6
[[a.c.d.e]]
gg = 7
[a.c.d.e.f]
hh = 8
[[b]]
ii = 9
[[b]]
jj = 10
[b.a]
kk = 11
[this.is-a."complex" . 'table' . name]
ok = true

47
tests/example.toml Normal file
View File

@@ -0,0 +1,47 @@
# This is a TOML document. Boom.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
organization = "GitHub"
bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
# dob = 1979-05-27T07:32:00Z # First class dates? Why not?
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
[servers]
# You can indent as you please. Tabs or spaces. TOML don't care.
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
country = "中国" # This should be parsed as UTF-8
[clients]
data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]
# Products
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
name = "Nail"
sku = 284758393
color = "gray"

13
tests/fruit.toml Normal file
View File

@@ -0,0 +1,13 @@
[[fruit.blah]]
name = "apple"
[fruit.blah.physical]
color = "red"
shape = "round"
[[fruit.blah]]
name = "banana"
[fruit.blah.physical]
color = "yellow"
shape = "bent"

33
tests/hard_example.toml Normal file
View File

@@ -0,0 +1,33 @@
# Test file for TOML
# Only this one tries to emulate a TOML file written by a user of the kind of parser writers probably hate
# This part you'll really hate
[the]
test_string = "You'll hate me after this - #" # " Annoying, isn't it?
[the.hard]
test_array = [ "] ", " # "] # ] There you go, parse this!
test_array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ]
# You didn't think it'd as easy as chucking out the last #, did you?
another_test_string = " Same thing, but with a string #"
harder_test_string = " And when \"'s are in the string, along with # \"" # "and comments are there too"
# Things will get harder
[the.hard."bit#"]
"what?" = "You don't think some user won't do that?"
multi_line_array = [
"]",
# ] Oh yes I did
]
# Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
#[error] if you didn't catch this, your parser is broken
#string = "Anything other than tabs, spaces and newline after a keygroup or key value pair has ended should produce an error unless it is a comment" like this
#array = [
# "This might most likely happen in multiline arrays",
# Like here,
# "or here,
# and here"
# ] End of array comment, forgot the #
#number = 3.14 pi <--again forgot the #

View File

@@ -0,0 +1,36 @@
# Tèƨƭ ƒïℓè ƒôř TÓM£
# Óñℓ¥ ƭλïƨ ôñè ƭřïèƨ ƭô è₥úℓáƭè á TÓM£ ƒïℓè ωřïƭƭèñ β¥ á úƨèř ôƒ ƭλè ƙïñδ ôƒ ƥářƨèř ωřïƭèřƨ ƥřôβáβℓ¥ λáƭè
# Tλïƨ ƥářƭ ¥ôú' řèáℓℓ¥ λáƭè
[the]
test_string = "Ýôú' λáƭè ₥è áƒƭèř ƭλïƨ - #" # " Âññô¥ïñϱ, ïƨñ'ƭ ïƭ?
[the.hard]
test_array = [ "] ", " # "] # ] Tλèřè ¥ôú ϱô, ƥářƨè ƭλïƨ!
test_array2 = [ "Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ", "Éжƥèřï₥èñƭ #9 ωáƨ á ƨúççèƨƨ" ]
# Ýôú δïδñ'ƭ ƭλïñƙ ïƭ'δ áƨ èáƨ¥ áƨ çλúçƙïñϱ ôúƭ ƭλè ℓáƨƭ #, δïδ ¥ôú?
another_test_string = "§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #"
harder_test_string = " Âñδ ωλèñ \"'ƨ ářè ïñ ƭλè ƨƭřïñϱ, áℓôñϱ ωïƭλ # \"" # "áñδ çô₥₥èñƭƨ ářè ƭλèřè ƭôô"
# Tλïñϱƨ ωïℓℓ ϱèƭ λářδèř
[the.hard."βïƭ#"]
"ωλáƭ?" = "Ýôú δôñ'ƭ ƭλïñƙ ƨô₥è úƨèř ωôñ'ƭ δô ƭλáƭ?"
multi_line_array = [
"]",
# ] Óλ ¥èƨ Ì δïδ
]
# Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
#[error] ïƒ ¥ôú δïδñ'ƭ çáƭçλ ƭλïƨ, ¥ôúř ƥářƨèř ïƨ βřôƙèñ
#string = "Âñ¥ƭλïñϱ ôƭλèř ƭλáñ ƭáβƨ, ƨƥáçèƨ áñδ ñèωℓïñè áƒƭèř á ƙè¥ϱřôúƥ ôř ƙè¥ Ʋáℓúè ƥáïř λáƨ èñδèδ ƨλôúℓδ ƥřôδúçè áñ èřřôř úñℓèƨƨ ïƭ ïƨ á çô₥₥èñƭ" ℓïƙè ƭλïƨ
#array = [
# "Tλïƨ ₥ïϱλƭ ₥ôƨƭ ℓïƙèℓ¥ λáƥƥèñ ïñ ₥úℓƭïℓïñè ářřá¥ƨ",
# £ïƙè λèřè,
# "ôř λèřè,
# áñδ λèřè"
# ] Éñδ ôƒ ářřᥠçô₥₥èñƭ, ƒôřϱôƭ ƭλè #
#number = 3.14 ƥï <--áϱáïñ ƒôřϱôƭ ƭλè #

115
tests/key-values.toml Normal file
View File

@@ -0,0 +1,115 @@
# All kinds of keys and string values
key1-bare-with-dash = "basic string 1"
key2-bare_with_underscore = 'literal string 2'
3-key-start-with-digit = "basic string \b 3 with \t space \f and\"escapes \\\u05d0\n"
"key 4 double quoted\n" = "basic string \rbasic string with carriage return"
'key 5 single quoted' = """multi line basic string"""
'key 6 multi-line basic string strip beginning new line' = """
There should be no new line, but two leading spaces."""
'key 7 line ending backslash' = """
lines with \
ending backslash \
should be concatenated into a single line and \
new lines and spaces after the line ending backslash should be stripped."""
'key 8 multi-line basic string with escapes' = """
Escapes \b
should\t
also \f
work \"
in \\
multi-line \nbasic string."""
'key 9 multi-line literal string' = '''
The first newline is
trimmed in raw strings.
All other whitespace or [(*&%$@!/\~`^#)]
is preserved.
'''
# Numbers, copied from README.md on https://github.com/toml-lang/toml
int1 = +99
int2 = 42
int3 = 0
int4 = -17
int5 = 1_000
int6 = 5_349_221
int7 = 1_2_3_4_5 # VALID but discouraged
# hexadecimal with prefix `0x`
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef
# octal with prefix `0o`
oct1 = 0o01234567
oct2 = 0o755 # useful for Unix file permissions
oct3 = 0o0123_4567
oct4 = 0o7_5_5
# binary with prefix `0b`
bin1 = 0b11010110
bin2 = 0b1101_0110
# fractional
flt1 = +1.0
flt2 = 3.1415
flt3 = -0.01
# exponent
flt4 = 5e+22
flt5 = 1e6
flt6 = -2E-2
# both
flt7 = 6.626e-34
flt8 = 9_224_617.445_991_228_313
# infinity
sf1 = inf # positive infinity
sf2 = +inf # positive infinity
sf3 = -inf # negative infinity
# not a number
sf4 = nan # actual sNaN/qNaN encoding is implementation specific
sf5 = +nan # same as `nan`
sf6 = -nan # valid, actual encoding is implementation specific
# Boolean
bool1 = true
bool2 = false
# Array
arr1 = [ 1, 2, 3 ]
arr2 = [ "red", "yellow", "green" ]
arr3 = [ [ 1, 2 ], [3, 4, 5] ]
arr4 = [ "all", 'strings', """are the same""", '''type''']
arr5 = [ [ 1, 2 ], ["a", "b", "c"] ]
#arr6 = [ 1, 2.0 ] # INVALID
arr7 = [
1, 2, 3
]
arr8 = [
1,
2, # this is ok
]
# Inline tables
name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }
points = [ { x = 1, y = 2, z = 3 },
{ x = 7, y = 8, z = 9 },
{ x = 2, y = 4, z = 8 } ]

132
tests/long_config.toml Normal file
View File

@@ -0,0 +1,132 @@
[voice-5band-compressor]
input = "voice_44k_16bit_1ch.wav"
output = "voice_44k_16bit_2ch_5band_compressor.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, true, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]
[MultibandCompressor-SweepLevelChange-5Bands-LR-32k]
input = "SweepLevelChange_32k_LR_2ch.wav"
output = "MultibandCompressor_SweepLevelChange_5Bands_LR_32k.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, true, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]
[MultibandCompressor-SweepLevelChange-5Bands-LR-44k]
input = "SweepLevelChange_44k_LR_2ch.wav"
output = "MultibandCompressor_SweepLevelChange_5Bands_LR_44k.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, true, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]
[MultibandCompressor-SweepLevelChange-5Bands-LR-48k]
input = "SweepLevelChange_48k_LR_2ch.wav"
output = "MultibandCompressor_SweepLevelChange_5Bands_LR_48k.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, true, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]
[MultibandCompressor-SweepLevelChange-5Bands-1BandBypass-LR-32k]
input = "SweepLevelChange_32k_LR_2ch.wav"
output = "MultibandCompressor_SweepLevelChange_5Bands_1BandBypass_LR_32k.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, false, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]
[MultibandCompressor-SweepLevelChange-5Bands-1BandBypass-LR-44k]
input = "SweepLevelChange_44k_LR_2ch.wav"
output = "MultibandCompressor_SweepLevelChange_5Bands_1BandBypass_LR_44k.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, false, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]
[MultibandCompressor-SweepLevelChange-5Bands-1BandBypass-LR-48k]
input = "SweepLevelChange_48k_LR_2ch.wav"
output = "MultibandCompressor_SweepLevelChange_5Bands_1BandBypass_LR_48k.wav"
sidechain = "WhiteNoiseChange_44.1k_16bit_1ch.wav"
block-size = 256
out-channels = 2
bandnum = 5
enabled = [true, true, true, false, true]
threshold = [-60.0, -10.0, -10.0, -10.0, -10.0]
ratio = [1.5, 1.5, 1.5, 1.5, 1.5]
attack-time = [30, 40, 50, 60, 70]
release-time = [100, 110, 120, 130, 140]
averaging-time = [30, 40, 50, 60, 70]
crossover_fc = [500.0, 1000.0, 4000.0, 10000.0]
saturation-threshold = [-1.0, -1.0, -1.0, -1.0, -1.0]
input-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
output-gain = [1.0, 1.0, 1.0, 1.0, 1.0]
side_chain_enabled = [true, true, true, true, true]

139
tests/main.c Normal file
View File

@@ -0,0 +1,139 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <inttypes.h>
#include "tlibtoml/toml.h"
#ifndef PROJECT_SOURCE_DIR
#define PROJECT_SOURCE_DIR ".."
#endif
void print_table(const TomlTable *table);
void print_value(const TomlValue *value);
void print_array(const TomlArray *array)
{
printf("[");
for (size_t i = 0; i < array->len; i++) {
if (i > 0) {
printf(", ");
}
print_value(array->elements[i]);
}
printf("]");
}
void print_value(const TomlValue *value)
{
switch (value->type) {
case TOML_TABLE:
print_table(value->value.table);
break;
case TOML_ARRAY:
print_array(value->value.array);
break;
case TOML_STRING:
printf("\"%s\"", value->value.string->str);
break;
case TOML_INTEGER:
printf("%" PRId64, value->value.integer);
break;
case TOML_FLOAT:
printf("%f", value->value.float_);
break;
case TOML_DATETIME:
printf("(datetime)");
break;
case TOML_BOOLEAN:
printf("%s", value->value.boolean ? "true" : "false");
break;
}
}
void print_keyval(const TomlKeyValue *keyval)
{
printf("\"%s\": ", keyval->key->str);
print_value(keyval->value);
}
void print_table(const TomlTable *table)
{
TomlTableIter it = toml_table_iter_new((TomlTable *)table);
printf("{");
size_t i = 0;
while (toml_table_iter_has_next(&it)) {
TomlKeyValue *keyval = toml_table_iter_get(&it);
if (i > 0) {
printf(", ");
}
print_keyval(keyval);
toml_table_iter_next(&it);
i++;
}
printf("}");
}
int test_run(const char *filename)
{
TomlTable *table = NULL;
int rc = 0;
table = toml_load_filename(filename);
if (table == NULL)
goto cleanup;
print_table(table);
printf("\n");
cleanup:
toml_table_free(table);
if (toml_err()->code != TOML_OK) {
fprintf(stderr, "%s\n", toml_err()->message);
rc = (int)toml_err()->code;
}
toml_err_clear();
return rc;
}
int main(void)
{
static const char *const filenames[] = {
/* should parse */
PROJECT_SOURCE_DIR "/tests/key-values.toml",
PROJECT_SOURCE_DIR "/tests/complex-structure.toml",
PROJECT_SOURCE_DIR "/tests/long_config.toml",
/* should not parse */
/* tests from https://github.com/toml-lang/toml */
PROJECT_SOURCE_DIR "/tests/example.toml",
PROJECT_SOURCE_DIR "/tests/fruit.toml",
PROJECT_SOURCE_DIR "/tests/hard_example.toml",
PROJECT_SOURCE_DIR "/tests/hard_example_unicode.toml"
};
int total_tests = sizeof(filenames) / sizeof(char *);
int num_passed = 0;
int num_failed = 0;
for (int i = 0; i < total_tests; i++) {
int rc = test_run(filenames[i]);
if (rc == 0) {
printf("test %d success\n", i);
num_passed++;
} else {
printf("test %d returned %d\n", i, rc);
num_failed++;
}
}
printf("total %d tests, %d passed, %d failed\n",
total_tests, num_passed, num_failed);
return num_failed;
}