828f171a97ba1eeb85665cf604fbcf7d85ea393c
[platform/upstream/iotjs.git] / tools / test / run_pass / test_assert.js
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 var assert = require('assert');
17
18
19 assert.assert(1 == 1);
20
21 assert.equal(1, 1);
22 assert.notEqual(1, 2);
23
24 assert.strictEqual(0, 0);
25
26 assert.equal(0, false);
27 assert.notStrictEqual(0, false);
28
29 assert.throws(
30   function() {
31     assert.equal(1, 2);
32   },
33   assert.AssertionError
34 );
35
36 assert.throws(
37   function() {
38     assert.assert(1 == 2);
39   },
40   assert.AssertionError
41 );
42
43 assert.doesNotThrow(
44   function() {
45     assert.assert(1 == 1);
46   }
47 );
48
49 assert.throws(
50   function() {
51     assert.doesNotThrow(
52       function() {
53         assert.assert(1 == 2);
54       }
55     );
56   },
57   assert.AssertionError
58 );
59
60 try {
61   assert.assert(false, 'assert test');
62 } catch (e) {
63   assert.equal(e.name, 'AssertionError');
64   assert.equal(e.actual, false);
65   assert.equal(e.expected, true);
66   assert.equal(e.operator, '==');
67   assert.equal(e.message, 'assert test');
68 }
69
70 try {
71   assert.equal(1, 2, 'assert.equal test');
72 } catch (e) {
73   assert.equal(e.name, 'AssertionError');
74   assert.equal(e.actual, 1);
75   assert.equal(e.expected, 2);
76   assert.equal(e.operator, '==');
77   assert.equal(e.message, 'assert.equal test');
78 }
79
80
81 try {
82   assert.fail('actual', 'expected', 'message', 'operator');
83 } catch (e) {
84   assert.equal(e.name, 'AssertionError');
85   assert.equal(e.actual, 'actual');
86   assert.equal(e.expected, 'expected');
87   assert.equal(e.operator, 'operator');
88   assert.equal(e.message, 'message');
89 }