fixes for null vs 0, and support for assert +test
This commit is contained in:
Родитель
3c5c095e65
Коммит
e5847048c3
|
@ -68,6 +68,7 @@ function pointingLevels(type) {
|
|||
|
||||
function toNiceIdent(ident) {
|
||||
if (parseFloat(ident) == ident) return ident;
|
||||
if (ident == 'null') return '0'; // see parseNumerical
|
||||
return ident.replace(/[" \.@%:<>,\*]/g, '_');
|
||||
}
|
||||
|
||||
|
@ -325,6 +326,10 @@ function parseNumerical(value, type) {
|
|||
// "The one non-intuitive notation for constants is the hexadecimal form of floating point constants."
|
||||
return IEEEUnHex(value);
|
||||
}
|
||||
if (value == 'null') {
|
||||
// NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.)
|
||||
return '0';
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -2139,12 +2144,11 @@ function JSify(data) {
|
|||
item.JS = (item.overrideSSA ? '' : 'var ') + toNiceIdent(item.ident);
|
||||
|
||||
var type = item.value.type.text;
|
||||
var value = item.value.JS;
|
||||
var value = parseNumerical(item.value.JS);
|
||||
//print("zz var: " + item.JS);
|
||||
var impl = getVarData(item.funcData, item.ident);
|
||||
switch (impl) {
|
||||
case VAR_NATIVE: {
|
||||
value = parseNumerical(value, type);
|
||||
break;
|
||||
}
|
||||
case VAR_NATIVIZED: {
|
||||
|
|
|
@ -56,6 +56,10 @@ var Snippets = {
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
__assert_fail: function(condition, file, line) {
|
||||
throw 'Assertion failed: ' + Pointer_stringify(condition);//JSON.stringify(arguments)//condition;
|
||||
},
|
||||
};
|
||||
|
||||
// Aliases
|
||||
|
|
|
@ -357,11 +357,25 @@ class T(unittest.TestCase):
|
|||
c = c->next;
|
||||
} while (c != chunk);
|
||||
|
||||
printf("*%d*\\n", total);
|
||||
printf("*%d,%d*\\n", total, b.next);
|
||||
// NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.)
|
||||
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
self.do_test(src, '*1410*')
|
||||
self.do_test(src, '*1410,0*')
|
||||
|
||||
def test_assert(self):
|
||||
src = '''
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
int main() {
|
||||
assert(1 == true); // pass
|
||||
assert(1 == false); // fail
|
||||
return 1;
|
||||
}
|
||||
'''
|
||||
self.do_test(src, 'Assertion failed: 1 == false')
|
||||
|
||||
def test_class(self):
|
||||
src = '''
|
||||
|
|
Загрузка…
Ссылка в новой задаче