Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1754)

Unified Diff: test/cctest/test-code-stub-assembler.cc

Issue 2438483002: Add tests for CodeStubAssembler::ToString (Closed)
Patch Set: updates Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-code-stub-assembler.cc
diff --git a/test/cctest/test-code-stub-assembler.cc b/test/cctest/test-code-stub-assembler.cc
index 5ea21ca37aa51b27ac1bf06ee25fcd78a48a799d..68c56bba34a3ba37efb2f44235131dc107c58728 100644
--- a/test/cctest/test-code-stub-assembler.cc
+++ b/test/cctest/test-code-stub-assembler.cc
@@ -119,6 +119,62 @@ TEST(ComputeIntegerHash) {
}
}
+TEST(ToString) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+ const int kNumParams = 1;
+ CodeStubAssemblerTester m(isolate, kNumParams);
+ m.Return(m.ToString(m.Parameter(kNumParams + 2), m.Parameter(0)));
+
+ Handle<Code> code = m.GenerateCode();
+ FunctionTester ft(code, kNumParams);
+
+ Handle<FixedArray> test_cases = isolate->factory()->NewFixedArray(5);
+ Handle<FixedArray> smi_test = isolate->factory()->NewFixedArray(2);
+ smi_test->set(0, Smi::FromInt(42));
+ Handle<String> str(isolate->factory()->InternalizeUtf8String("42"));
+ smi_test->set(1, *str);
+ test_cases->set(0, *smi_test);
+
+ Handle<FixedArray> number_test = isolate->factory()->NewFixedArray(2);
+ Handle<HeapNumber> num(isolate->factory()->NewHeapNumber(3.14));
+ number_test->set(0, *num);
+ str = isolate->factory()->InternalizeUtf8String("3.14");
+ number_test->set(1, *str);
+ test_cases->set(1, *number_test);
+
+ Handle<FixedArray> string_test = isolate->factory()->NewFixedArray(2);
+ str = isolate->factory()->InternalizeUtf8String("test");
+ string_test->set(0, *str);
+ string_test->set(1, *str);
+ test_cases->set(2, *string_test);
+
+ Handle<FixedArray> oddball_test = isolate->factory()->NewFixedArray(2);
+ oddball_test->set(0, isolate->heap()->undefined_value());
+ str = isolate->factory()->InternalizeUtf8String("undefined");
+ oddball_test->set(1, *str);
+ test_cases->set(3, *oddball_test);
+
+ Handle<FixedArray> tostring_test = isolate->factory()->NewFixedArray(2);
+ Handle<FixedArray> js_array_storage = isolate->factory()->NewFixedArray(2);
+ js_array_storage->set(0, Smi::FromInt(1));
+ js_array_storage->set(1, Smi::FromInt(2));
+ Handle<JSArray> js_array = isolate->factory()->NewJSArray(2);
+ JSArray::SetContent(js_array, js_array_storage);
+ tostring_test->set(0, *js_array);
+ str = isolate->factory()->InternalizeUtf8String("1,2");
+ tostring_test->set(1, *str);
+ test_cases->set(4, *tostring_test);
+
+ for (int i = 0; i < 5; ++i) {
+ Handle<FixedArray> test = handle(FixedArray::cast(test_cases->get(i)));
+ Handle<Object> obj = handle(test->get(0), isolate);
+ Handle<String> expected = handle(String::cast(test->get(1)));
+ Handle<Object> result = ft.Call(obj).ToHandleChecked();
+ CHECK(result->IsString());
+ CHECK(String::Equals(Handle<String>::cast(result), expected));
+ }
+}
+
TEST(TryToName) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698