2017-10-13 18:23:53 +00:00
|
|
|
// 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"
|
2017-10-27 19:53:15 +00:00
|
|
|
#include "src/ast/ast.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate-inl.h"
|
2017-10-13 18:23:53 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/numbers/hash-seed-inl.h"
|
2017-10-13 18:23:53 +00:00
|
|
|
#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(),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(i_isolate())),
|
2017-10-27 19:53:15 +00:00
|
|
|
ast_node_factory_(&ast_value_factory_, zone()) {}
|
|
|
|
|
|
|
|
Literal* NewBigInt(const char* str) {
|
|
|
|
return ast_node_factory_.NewBigIntLiteral(AstBigInt(str),
|
|
|
|
kNoSourcePosition);
|
|
|
|
}
|
2017-10-13 18:23:53 +00:00
|
|
|
|
|
|
|
AstValueFactory ast_value_factory_;
|
2017-10-27 19:53:15 +00:00
|
|
|
AstNodeFactory ast_node_factory_;
|
2017-10-13 18:23:53 +00:00
|
|
|
};
|
|
|
|
|
2017-10-27 19:53:15 +00:00
|
|
|
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());
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_TRUE(NewBigInt("0xA")->ToBooleanIsTrue());
|
2017-10-27 19:53:15 +00:00
|
|
|
EXPECT_TRUE(NewBigInt("0b0000001")->ToBooleanIsTrue());
|
|
|
|
EXPECT_TRUE(NewBigInt("0o00005000")->ToBooleanIsTrue());
|
2017-12-02 00:30:37 +00:00
|
|
|
EXPECT_TRUE(NewBigInt("0x0000D00C0")->ToBooleanIsTrue());
|
2017-10-13 18:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|