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

Unified Diff: test/cctest/test-parsing.cc

Issue 1201783003: Allow numeric literals to be checked for a decimal point. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 5 years, 6 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 | « src/scanner.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index a4293d662af36426f38b7c4863a3dea33892b7a5..88dadcb1bf8ba35db6d0d986065e2f52ca370350 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1100,6 +1100,58 @@ TEST(ScopeUsesArgumentsSuperThis) {
}
+static void CheckParsesToNumber(const char* source, bool with_dot) {
+ v8::V8::Initialize();
+ HandleAndZoneScope handles;
+
+ i::Isolate* isolate = CcTest::i_isolate();
+ i::Factory* factory = isolate->factory();
+
+ std::string full_source = "function f() { return ";
+ full_source += source;
+ full_source += "; }";
+
+ i::Handle<i::String> source_code =
+ factory->NewStringFromUtf8(i::CStrVector(full_source.c_str()))
+ .ToHandleChecked();
+
+ i::Handle<i::Script> script = factory->NewScript(source_code);
+
+ i::ParseInfo info(handles.main_zone(), script);
+ i::Parser parser(&info);
+ parser.set_allow_harmony_arrow_functions(true);
+ parser.set_allow_harmony_sloppy(true);
+ info.set_global();
+ info.set_lazy(false);
+ info.set_allow_lazy_parsing(false);
+ info.set_toplevel(true);
+
+ i::CompilationInfo compilation_info(&info);
+ CHECK(i::Compiler::ParseAndAnalyze(&info));
+
+ CHECK(info.scope()->declarations()->length() == 1);
+ i::FunctionLiteral* fun =
+ info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun();
+ CHECK(fun->body()->length() == 1);
+ CHECK(fun->body()->at(0)->IsReturnStatement());
+ i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement();
+ CHECK(ret->expression()->IsLiteral());
+ i::Literal* lit = ret->expression()->AsLiteral();
+ const i::AstValue* val = lit->raw_value();
+ CHECK(with_dot == val->ContainsDot());
+}
+
+
+TEST(ParseNumbers) {
+ CheckParsesToNumber("1.34", true);
+ CheckParsesToNumber("134", false);
+ CheckParsesToNumber("134e44", false);
+ CheckParsesToNumber("134.e44", true);
+ CheckParsesToNumber("134.44e44", true);
+ CheckParsesToNumber(".44", true);
+}
+
+
TEST(ScopePositions) {
// Test the parser for correctly setting the start and end positions
// of a scope. We check the scope positions of exactly one scope
« no previous file with comments | « src/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698