summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/parser/ast-value-unittest.cc
blob: c30823b4b146b2cb7f52276e38ccbab9716b071e (plain)
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
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/ast/ast-value-factory.h"
#include "src/ast/ast.h"
#include "src/hash-seed-inl.h"
#include "src/heap/heap-inl.h"
#include "src/isolate-inl.h"
#include "src/zone/zone.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace v8 {
namespace internal {

class AstValueTest : public TestWithIsolateAndZone {
 protected:
  AstValueTest()
      : ast_value_factory_(zone(), i_isolate()->ast_string_constants(),
                           HashSeed(i_isolate())),
        ast_node_factory_(&ast_value_factory_, zone()) {}

  Literal* NewBigInt(const char* str) {
    return ast_node_factory_.NewBigIntLiteral(AstBigInt(str),
                                              kNoSourcePosition);
  }

  AstValueFactory ast_value_factory_;
  AstNodeFactory ast_node_factory_;
};

TEST_F(AstValueTest, BigIntToBooleanIsTrue) {
  EXPECT_FALSE(NewBigInt("0")->ToBooleanIsTrue());
  EXPECT_FALSE(NewBigInt("0b0")->ToBooleanIsTrue());
  EXPECT_FALSE(NewBigInt("0o0")->ToBooleanIsTrue());
  EXPECT_FALSE(NewBigInt("0x0")->ToBooleanIsTrue());
  EXPECT_FALSE(NewBigInt("0b000")->ToBooleanIsTrue());
  EXPECT_FALSE(NewBigInt("0o00000")->ToBooleanIsTrue());
  EXPECT_FALSE(NewBigInt("0x000000000")->ToBooleanIsTrue());

  EXPECT_TRUE(NewBigInt("3")->ToBooleanIsTrue());
  EXPECT_TRUE(NewBigInt("0b1")->ToBooleanIsTrue());
  EXPECT_TRUE(NewBigInt("0o6")->ToBooleanIsTrue());
  EXPECT_TRUE(NewBigInt("0xA")->ToBooleanIsTrue());
  EXPECT_TRUE(NewBigInt("0b0000001")->ToBooleanIsTrue());
  EXPECT_TRUE(NewBigInt("0o00005000")->ToBooleanIsTrue());
  EXPECT_TRUE(NewBigInt("0x0000D00C0")->ToBooleanIsTrue());
}

}  // namespace internal
}  // namespace v8