Line data Source code
1 : // Copyright 2017 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/ast/ast-value-factory.h"
6 : #include "src/ast/ast.h"
7 : #include "src/hash-seed-inl.h"
8 : #include "src/heap/heap-inl.h"
9 : #include "src/isolate-inl.h"
10 : #include "src/zone/zone.h"
11 : #include "test/unittests/test-utils.h"
12 : #include "testing/gtest/include/gtest/gtest.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 2 : class AstValueTest : public TestWithIsolateAndZone {
18 : protected:
19 1 : AstValueTest()
20 : : ast_value_factory_(zone(), i_isolate()->ast_string_constants(),
21 : HashSeed(i_isolate())),
22 2 : ast_node_factory_(&ast_value_factory_, zone()) {}
23 :
24 : Literal* NewBigInt(const char* str) {
25 : return ast_node_factory_.NewBigIntLiteral(AstBigInt(str),
26 : kNoSourcePosition);
27 : }
28 :
29 : AstValueFactory ast_value_factory_;
30 : AstNodeFactory ast_node_factory_;
31 : };
32 :
33 15444 : TEST_F(AstValueTest, BigIntToBooleanIsTrue) {
34 2 : EXPECT_FALSE(NewBigInt("0")->ToBooleanIsTrue());
35 2 : EXPECT_FALSE(NewBigInt("0b0")->ToBooleanIsTrue());
36 2 : EXPECT_FALSE(NewBigInt("0o0")->ToBooleanIsTrue());
37 2 : EXPECT_FALSE(NewBigInt("0x0")->ToBooleanIsTrue());
38 2 : EXPECT_FALSE(NewBigInt("0b000")->ToBooleanIsTrue());
39 2 : EXPECT_FALSE(NewBigInt("0o00000")->ToBooleanIsTrue());
40 2 : EXPECT_FALSE(NewBigInt("0x000000000")->ToBooleanIsTrue());
41 :
42 2 : EXPECT_TRUE(NewBigInt("3")->ToBooleanIsTrue());
43 2 : EXPECT_TRUE(NewBigInt("0b1")->ToBooleanIsTrue());
44 2 : EXPECT_TRUE(NewBigInt("0o6")->ToBooleanIsTrue());
45 2 : EXPECT_TRUE(NewBigInt("0xA")->ToBooleanIsTrue());
46 2 : EXPECT_TRUE(NewBigInt("0b0000001")->ToBooleanIsTrue());
47 2 : EXPECT_TRUE(NewBigInt("0o00005000")->ToBooleanIsTrue());
48 2 : EXPECT_TRUE(NewBigInt("0x0000D00C0")->ToBooleanIsTrue());
49 1 : }
50 :
51 : } // namespace internal
52 9264 : } // namespace v8
|