forked from danbev/learning-v8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.cc
51 lines (46 loc) · 1.55 KB
/
string_test.cc
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
#include <iostream>
#include "gtest/gtest.h"
#include "v8.h"
#include "libplatform/libplatform.h"
#include "v8_test_fixture.h"
using namespace v8;
class StringTest : public V8TestFixture {
};
TEST_F(StringTest, create) {
const v8::HandleScope handle_scope(isolate_);
Isolate::Scope isolate_scope(isolate_);
Local<String> str = String::NewFromOneByte(isolate_,
reinterpret_cast<const uint8_t*>("bajja"),
NewStringType::kNormal,
6).ToLocalChecked();
String::Utf8Value value(str);
EXPECT_STREQ("bajja", *value);
EXPECT_EQ(str->Length(), 6);
EXPECT_EQ(str->Utf8Length(), 6);
EXPECT_EQ(str->IsOneByte(), true);
EXPECT_EQ(str->IsExternal(), false);
EXPECT_EQ(str->IsExternalOneByte(), false);
}
TEST_F(StringTest, empty) {
const v8::HandleScope handle_scope(isolate_);
Isolate::Scope isolate_scope(isolate_);
Local<String> str = String::Empty(isolate_);
EXPECT_EQ(str->Length(), 0);
EXPECT_EQ(str->Utf8Length(), 0);
EXPECT_EQ(str->IsOneByte(), true);
EXPECT_EQ(str->ContainsOnlyOneByte(), true);
}
TEST_F(StringTest, concat) {
const v8::HandleScope handle_scope(isolate_);
Isolate::Scope isolate_scope(isolate_);
Local<String> left = String::NewFromOneByte(isolate_,
reinterpret_cast<const uint8_t*>("hey"),
NewStringType::kNormal,
6).ToLocalChecked();
Local<String> right = String::NewFromOneByte(isolate_,
reinterpret_cast<const uint8_t*>(" bajja"),
NewStringType::kNormal,
6).ToLocalChecked();
Local<String> joined = String::Concat(left, right);
EXPECT_EQ(joined->Length(), 12);
}