Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDAlexander77 committed May 24, 2020
1 parent dce0fdf commit e7fecbf
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 14 deletions.
11 changes: 9 additions & 2 deletions cpplib/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2406,11 +2406,11 @@ struct any

if (get_type() == anyTypeId::string_type)
{
char_t* end;
#ifdef UNICODE
wchar_t* end;
return js::number(std::wcstof(string_ref().operator const char_t *(), &end));
#else
return js::number(std::atof(string_ref().operator const char_t *()));
return js::number(std::strtof(string_ref().operator const char_t *(), &end));
#endif
}

Expand Down Expand Up @@ -2508,6 +2508,13 @@ struct any
return boolean_ref() ? 1 : 0;
case anyTypeId::number_type:
return number_ref();
case anyTypeId::string_type:
char_t* end;
#ifdef UNICODE
return static_cast<N>(std::wcstof(string_ref().operator const char_t *(), &end));
#else
return static_cast<N>(std::strtof(string_ref().operator const char_t *(), &end));
#endif
}

throw "wrong type";
Expand Down
135 changes: 123 additions & 12 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,123 @@
let isDone1: boolean = false;
const isDone2: boolean = false;
var isDone3: boolean = false;
let val1: any = null;
const val2: any = null;
var val3: any = null;
console.log(isDone1);
console.log(isDone2);
console.log(isDone3);
console.log(val1);
console.log(val2);
console.log(val3);


//
// Note that this is supposed to run from command line.
// Do not use anything besides pause, control.runInBackground, console.log
//

// pause(2000)
type uint8 number;
type int8 number;
type uint16 number;
type int16 number;

namespace control {
function runInBackground(f: ()=>void): void {
thread(f);
}

function dmesg(s: string): void {
}
}

function pause(t: number) {
sleep(t);
}

function msg(s: string): void {
console.log(s)
control.dmesg(s)
//pause(50);
}

msg("start!")

function assert(cond: boolean, m?: string) {
if (!cond) {
msg("assertion failed: ")
if (m) {
msg(m)
}

throw m;
}
}

//
// start tests
//

let glb1: number;
let s2: string;
let x: number;
let action: Action;
let tot: string;
let lazyAcc: number;
let sum: number;
let u8: uint8
let i8: int8
let u16: uint16
let i16: int16

let xyz = 12;


let hasFloat = true
if ((1 / 10) == 0) {
hasFloat = false
}

class Testrec {
str: string;
num: number;
_bool: boolean;
str2: string;
}

function clean() {
glb1 = 0
s2 = ""
x = 0
action = null
tot = ""
lazyAcc = 0
sum = 0
}
function eqOp() {
msg("eqOp")
let x = 12
assert((x += 10) == 22, "Y0")
assert(x == 22, "Y1")
x /= 2
assert(x == 11, "Y2")

let s = ("fo" + 1)
let t = ("ba" + 2)
s += t
assert(s == "fo1b" + "a2", "fb")
}

function eqOpString() {
msg("eqOpStr")
let x = "fo"
assert((x += "ba") == "foba", "SY0")
assert(x == "foba", "SY1")
}

eqOp()
eqOpString()

function eq<A, B>(a: A, b: B) { return a == b as any as A }

function eqG() {
assert(eq("2", 2), "2")
assert(eq(2, "2"), "2'")
assert(!eq("null", null), "=1")
assert(!eq(null, "null"), "=2")
assert(!eq("2", 3), "=3")
}

eqG()
clean()
msg("test OK!")


0 comments on commit e7fecbf

Please sign in to comment.