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

Side by Side 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: iteration... 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 unified diff | Download patch
« no previous file with comments | « src/scanner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 CHECK(scope->LookupThis()->is_used()); 1094 CHECK(scope->LookupThis()->is_used());
1095 } 1095 }
1096 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0, 1096 CHECK_EQ((source_data[i].expected & INNER_ARGUMENTS) != 0,
1097 scope->inner_uses_arguments()); 1097 scope->inner_uses_arguments());
1098 CHECK_EQ((source_data[i].expected & EVAL) != 0, scope->calls_eval()); 1098 CHECK_EQ((source_data[i].expected & EVAL) != 0, scope->calls_eval());
1099 } 1099 }
1100 } 1100 }
1101 } 1101 }
1102 1102
1103 1103
1104 static void CheckParsesToNumber(const char* source, bool with_dot) {
1105 v8::V8::Initialize();
bradn 2015/06/23 06:54:07 Any pointers on how to reduce this? Speaking of re
1106 HandleAndZoneScope handles;
1107
1108 i::Isolate* isolate = CcTest::i_isolate();
1109 i::Factory* factory = isolate->factory();
1110
1111 std::string full_source = "function f() { return ";
1112 full_source += source;
1113 full_source += "; }";
1114
1115 i::Handle<i::String> source_code =
1116 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str()))
1117 .ToHandleChecked();
1118
1119 i::Handle<i::Script> script = factory->NewScript(source_code);
1120
1121 i::ParseInfo info(handles.main_zone(), script);
1122 i::Parser parser(&info);
1123 parser.set_allow_harmony_classes(true);
1124 parser.set_allow_harmony_object_literals(true);
1125 parser.set_allow_harmony_arrow_functions(true);
1126 parser.set_allow_harmony_sloppy(true);
1127 info.set_global();
1128 info.set_lazy(false);
1129 info.set_allow_lazy_parsing(false);
1130 info.set_toplevel(true);
1131
1132 i::CompilationInfo compilation_info(&info);
1133 CHECK(i::Compiler::ParseAndAnalyze(&info));
1134
1135 CHECK(info.scope()->declarations()->length() == 1);
1136 i::FunctionLiteral* fun =
1137 info.scope()->declarations()->at(0)->AsFunctionDeclaration()->fun();
1138 CHECK(fun->body()->length() == 1);
1139 CHECK(fun->body()->at(0)->IsReturnStatement());
1140 i::ReturnStatement* ret = fun->body()->at(0)->AsReturnStatement();
1141 CHECK(ret->expression()->IsLiteral());
1142 i::Literal* lit = ret->expression()->AsLiteral();
1143 const i::AstValue* val = lit->raw_value();
1144 CHECK(with_dot == val->ContainsDot());
1145 }
1146
1147
1148 TEST(ParseNumbers) {
1149 CheckParsesToNumber("1.34", true);
1150 CheckParsesToNumber("134", false);
1151 CheckParsesToNumber("134e44", false);
1152 CheckParsesToNumber("134.e44", true);
1153 CheckParsesToNumber("134.44e44", true);
1154 CheckParsesToNumber(".44", true);
1155 }
1156
1157
1104 TEST(ScopePositions) { 1158 TEST(ScopePositions) {
1105 // Test the parser for correctly setting the start and end positions 1159 // Test the parser for correctly setting the start and end positions
1106 // of a scope. We check the scope positions of exactly one scope 1160 // of a scope. We check the scope positions of exactly one scope
1107 // nested in the global scope of a program. 'inner source' is the 1161 // nested in the global scope of a program. 'inner source' is the
1108 // source code that determines the part of the source belonging 1162 // source code that determines the part of the source belonging
1109 // to the nested scope. 'outer_prefix' and 'outer_suffix' are 1163 // to the nested scope. 'outer_prefix' and 'outer_suffix' are
1110 // parts of the source that belong to the global scope. 1164 // parts of the source that belong to the global scope.
1111 struct SourceData { 1165 struct SourceData {
1112 const char* outer_prefix; 1166 const char* outer_prefix;
1113 const char* inner_source; 1167 const char* inner_source;
(...skipping 5584 matching lines...) Expand 10 before | Expand all | Expand 10 after
6698 kAllowHarmonyObjectLiterals, 6752 kAllowHarmonyObjectLiterals,
6699 kAllowHarmonySloppy, 6753 kAllowHarmonySloppy,
6700 }; 6754 };
6701 // clang-format on 6755 // clang-format on
6702 6756
6703 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, 6757 RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags,
6704 arraysize(always_flags)); 6758 arraysize(always_flags));
6705 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, 6759 RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags,
6706 arraysize(always_flags)); 6760 arraysize(always_flags));
6707 } 6761 }
OLDNEW
« 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