-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-meal.js
67 lines (55 loc) · 1.61 KB
/
test-meal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var addon = require('bindings')('exampleAddon');
var Meal = addon.Meal;
console.log("new Meal()");
var x = new Meal();
console.log(x);
console.log("");
console.log("new Meal('spaghetti')");
x = new Meal('spaghetti');
console.log(x);
console.log("");
console.log("new Meal('ramen', 2.0)");
x = new Meal('ramen', 2.0);
console.log(x);
console.log("");
console.log("new Meal('plate', 2.0) should throw exception");
try{
x = new Meal('plate', 2.0);
} catch (e) {
console.log(" ^Exception Caught: " + e);
}
console.log(x);
console.log("");
console.log(x);
console.log(".type = 'cupcake'");
x.type = 'cupcake';
console.log(" ^Assignment was ignored");
console.log(x);
console.log("");
console.log("");
console.log("Method overload #1: calling prepare('ramen', 0.5);");
x.prepare("ramen", 0.5);
console.log(" ==>Meal type is: " + x.type + ", and weight in " + x.size + 'kg');
console.log("");
console.log("Method overload #2: calling prepare('pasta');");
x.prepare("pasta");
console.log(" ==>Meal type is: " + x.type + ", and weight in " + x.size + 'kg');
try {
x.prepare("string-not-in-IDL-enum");
} catch (e) {
console.log("Caught exception when calling x.prepare(): " + e);
}
console.log("");
console.log("raw meal? " + (x.isRawMeal ? "Yes" : "Not any more"));
console.log('Call cook() method and waiting for promise...');
var timer = setInterval(function() {
process.stdout.write('.');
}, 100);
x.cook("Trump").then(
value => {
console.log(value);
console.log("raw meal? " + (x.isRawMeal ? "Yes" : "Not any more"));
clearInterval(timer);
}
);
console.log("raw meal? " + (x.isRawMeal ? "Yes" : "Not any more"));