diff options
author | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 15:17:42 +0200 |
---|---|---|
committer | Vasilis Kalintiris <ehostunreach@gmail.com> | 2013-12-07 19:35:59 +0200 |
commit | 4ca97d11ef6312c55b40c6a472adbb6f89eb09db (patch) | |
tree | 10c9d86a980c116f33cee6a64785e80e201aa493 /tests/test_core.py | |
parent | 94a032f5f8a56f419719a9a735b1a2c3981a9164 (diff) |
Use do_run_from_file() for test_sscanf
Diffstat (limited to 'tests/test_core.py')
-rw-r--r-- | tests/test_core.py | 102 |
1 files changed, 3 insertions, 99 deletions
diff --git a/tests/test_core.py b/tests/test_core.py index ffa43192..d4e7a5b4 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -3636,106 +3636,10 @@ ok def test_sscanf(self): if self.emcc_args is None: return self.skip('needs emcc for libc') - src = r''' - #include <stdio.h> - #include <string.h> - #include <stdlib.h> - - int main () { - #define CHECK(str) \ - { \ - char name[1000]; \ - memset(name, 0, 1000); \ - int prio = 99; \ - sscanf(str, "%s %d", name, &prio); \ - printf("%s : %d\n", name, prio); \ - } - CHECK("en-us 2"); - CHECK("en-r"); - CHECK("en 3"); - - printf("%f, %f\n", atof("1.234567"), atof("cheez")); - - char float_formats[] = "fegE"; - char format[] = "%_"; - for(int i = 0; i < 4; ++i) { - format[1] = float_formats[i]; - - float n = -1; - sscanf(" 2.8208", format, &n); - printf("%.4f\n", n); - - float a = -1; - sscanf("-3.03", format, &a); - printf("%.4f\n", a); - } - - char buffy[100]; - sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy); - printf("|%s|\n", buffy); - - int numverts = -1; - printf("%d\n", sscanf(" numverts 1499\n", " numverts %d", &numverts)); // white space is the same, even if tab vs space - printf("%d\n", numverts); - - int index; - float u, v; - short start, count; - printf("%d\n", sscanf(" vert 87 ( 0.481565 0.059481 ) 0 1\n", " vert %d ( %f %f ) %hu %hu", &index, &u, &v, &start, &count)); - printf("%d,%.6f,%.6f,%hu,%hu\n", index, u, v, start, count); - - int neg, neg2, neg3 = 0; - printf("%d\n", sscanf("-123 -765 -34-6", "%d %u %d", &neg, &neg2, &neg3)); - printf("%d,%u,%d\n", neg, neg2, neg3); - - { - int a = 0; - sscanf("1", "%i", &a); - printf("%i\n", a); - } - - char buf1[100], buf2[100], buf3[100], buf4[100]; - - int numItems = sscanf("level=4:ref=3", "%255[^:=]=%255[^:]:%255[^=]=%255c", buf1, buf2, buf3, buf4); - printf("%d, %s, %s, %s, %s\n", numItems, buf1, buf2, buf3, buf4); - - numItems = sscanf("def|456", "%[a-z]|%[0-9]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("3-4,-ab", "%[-0-9],%[ab-z-]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("Hello,World", "%[A-Za-z],%[^0-9]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); - - numItems = sscanf("Hello4711", "%[^0-9],%[^0-9]", buf1, buf2); - printf("%d, %s\n", numItems, buf1); - - numItems = sscanf("JavaScript", "%4[A-Za-z]", buf1); - printf("%d, %s\n", numItems, buf1); - - numItems = sscanf("[]", "%1[[]%1[]]", buf1, buf2); - printf("%d, %s, %s\n", numItems, buf1, buf2); + test_path = path_from_root('tests', 'core', 'test_sscanf') + src, output = (test_path + s for s in ('.in', '.out')) - return 0; - } - ''' - self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n2.8208\n-3.0300\n2.8208\n-3.0300\n2.8208\n-3.0300\n2.8208\n-3.0300\n|some|\n|something|\n|somethingmoar|\n' + - '1\n1499\n' + - '5\n87,0.481565,0.059481,0,1\n' + - '3\n-123,4294966531,-34\n' + - '1\n' + - '4, level, 4, ref, 3\n' + - '2, def, 456\n' + - '2, 3-4, -ab\n' + - '2, Hello, World\n' + - '1, Hello\n' + - '1, Java\n' + - '2, [, ]') + self.do_run_from_file(src, output) def test_sscanf_2(self): # doubles |