aboutsummaryrefslogtreecommitdiff
path: root/tests/test_core.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_core.py')
-rw-r--r--tests/test_core.py102
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