-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code is nearly untestable. fml
- Loading branch information
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
declare function $assert(value: any): boolean | ||
|
||
function bla() { | ||
return true | ||
} | ||
|
||
export default () => { | ||
|
||
const prom = new Promise((resolve, reject) => { | ||
resolve(true) | ||
}) | ||
|
||
const prom2 = new Promise((resolve, _) => { | ||
// Simulating a sleep because setTimeout does not exist | ||
for(let i = 1; i < 1000000; i++) {} | ||
resolve(true) | ||
}) | ||
|
||
const prom3 = new Promise((_, reject) => { | ||
// Simulating a sleep because setTimeout does not exist | ||
for(let i = 1; i < 1000000; i++) {} | ||
|
||
reject() | ||
}) | ||
|
||
// Support | ||
$assert(1) | ||
$assert(true) | ||
$assert(1 === 1) | ||
$assert(bla()) | ||
|
||
// No support | ||
$assert(() => true) // Use $assert((() => true)) immerdiate invoked function | ||
$assert(bla) // Use $assert(bla()) invoked function | ||
$assert(prom) | ||
$assert(prom2) | ||
$assert(prom3) | ||
|
||
return { | ||
namespace: { | ||
kind: "Namespace", | ||
apiVersion: "v1", | ||
metadata: {name: "Test"}, | ||
}, | ||
components: [], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
declare function $assert(value: any): boolean | ||
|
||
function bla() { | ||
return true | ||
} | ||
|
||
export default () => { | ||
|
||
const prom3 = new Promise((_, reject) => { | ||
// Simulating a sleep because setTimeout does not exist | ||
for(let i = 1; i < 1000000; i++) {} | ||
|
||
reject() | ||
}) | ||
|
||
// Support | ||
$assert(false) | ||
$assert(null) | ||
$assert(throw "") | ||
|
||
// No support | ||
$assert(() => true) // Use $assert((() => true)) immerdiate invoked function | ||
$assert(bla) // Use $assert(bla()) invoked function | ||
|
||
$assert(prom3) | ||
|
||
return { | ||
namespace: { | ||
kind: "Namespace", | ||
apiVersion: "v1", | ||
metadata: {name: "Test"}, | ||
}, | ||
components: [], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ts | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
code := Load("./testdata/success.ts", false) | ||
Run(code, ".") | ||
|
||
defer func() { _ = recover() }() | ||
|
||
code = Load("./testdata/panic.ts", false) | ||
Run(code, ".") | ||
|
||
t.Errorf("did not panic") | ||
} |