|
@@ -23,6 +23,7 @@ type
|
|
Procedure CreateParser(Const ASource : string; aVersion : TECMAVersion = TECMAVersion.ecma5);
|
|
Procedure CreateParser(Const ASource : string; aVersion : TECMAVersion = TECMAVersion.ecma5);
|
|
Procedure CheckClass(E : TJSElement; C : TJSElementClass);
|
|
Procedure CheckClass(E : TJSElement; C : TJSElementClass);
|
|
Procedure AssertEquals(Const AMessage : String; Expected, Actual : TJSType); overload;
|
|
Procedure AssertEquals(Const AMessage : String; Expected, Actual : TJSType); overload;
|
|
|
|
+ Procedure AssertEquals(Const AMessage : String; Expected, Actual : TJSVarType); overload;
|
|
Procedure AssertIdentifier(Msg : String; El : TJSElement; Const AName : TJSString);
|
|
Procedure AssertIdentifier(Msg : String; El : TJSElement; Const AName : TJSString);
|
|
Function GetSourceElements : TJSSourceElements;
|
|
Function GetSourceElements : TJSSourceElements;
|
|
Function GetVars : TJSElementNodes;
|
|
Function GetVars : TJSElementNodes;
|
|
@@ -99,8 +100,10 @@ type
|
|
procedure TestArrayExpressionStringArgs;
|
|
procedure TestArrayExpressionStringArgs;
|
|
procedure TestArrayExpressionIdentArgs;
|
|
procedure TestArrayExpressionIdentArgs;
|
|
Procedure TestVarDeclarationSimple;
|
|
Procedure TestVarDeclarationSimple;
|
|
|
|
+ Procedure TestLetDeclarationSimple;
|
|
procedure TestVarDeclarationDouble;
|
|
procedure TestVarDeclarationDouble;
|
|
procedure TestVarDeclarationSimpleInit;
|
|
procedure TestVarDeclarationSimpleInit;
|
|
|
|
+ procedure TestConstDeclarationSimpleInit;
|
|
procedure TestVarDeclarationDoubleInit;
|
|
procedure TestVarDeclarationDoubleInit;
|
|
procedure TestBlockEmpty;
|
|
procedure TestBlockEmpty;
|
|
procedure TestBlockEmptyStatement;
|
|
procedure TestBlockEmptyStatement;
|
|
@@ -154,6 +157,17 @@ begin
|
|
AssertEquals(AMessage,NE,NA);
|
|
AssertEquals(AMessage,NE,NA);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestJSParser.AssertEquals(const AMessage: String; Expected, Actual: TJSVarType);
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ NE,NA : String;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ NE:=GetEnumName(TypeInfo(TJSVarType),Ord(Expected));
|
|
|
|
+ NA:=GetEnumName(TypeInfo(TJSVarType),Ord(Actual));
|
|
|
|
+ AssertEquals(AMessage,NE,NA);
|
|
|
|
+end;
|
|
|
|
+
|
|
Procedure TTestJSParser.AssertIdentifier(Msg: String; El: TJSElement;
|
|
Procedure TTestJSParser.AssertIdentifier(Msg: String; El: TJSElement;
|
|
Const AName: TJSString);
|
|
Const AName: TJSString);
|
|
|
|
|
|
@@ -1563,8 +1577,24 @@ Var
|
|
begin
|
|
begin
|
|
CreateParser('var a;');
|
|
CreateParser('var a;');
|
|
X:=GetFirstVar;
|
|
X:=GetFirstVar;
|
|
|
|
+ AssertNotNull('Variable statement assigned',(X));
|
|
CheckClass(X,TJSVarDeclaration);
|
|
CheckClass(X,TJSVarDeclaration);
|
|
V:=TJSVarDeclaration(X);
|
|
V:=TJSVarDeclaration(X);
|
|
|
|
+ AssertEquals('correct variable type', vtVar, V.VarType);
|
|
|
|
+ AssertEquals('variable name correct registered', 'a', V.Name);
|
|
|
|
+ AssertNull('No initialization expression', V.Init);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestJSParser.TestLetDeclarationSimple;
|
|
|
|
+Var
|
|
|
|
+ X : TJSELement;
|
|
|
|
+ V : TJSVarDeclaration;
|
|
|
|
+begin
|
|
|
|
+ CreateParser('let a;',minLetVersion);
|
|
|
|
+ X:=GetFirstVar;
|
|
|
|
+ CheckClass(X,TJSVarDeclaration);
|
|
|
|
+ V:=TJSVarDeclaration(X);
|
|
|
|
+ AssertEquals('correct variable type', vtLet, V.VarType);
|
|
// AssertNotNull('Variable statement assigned',(X));
|
|
// AssertNotNull('Variable statement assigned',(X));
|
|
AssertEquals('variable name correct registered', 'a', V.Name);
|
|
AssertEquals('variable name correct registered', 'a', V.Name);
|
|
AssertNull('No initialization expression', V.Init);
|
|
AssertNull('No initialization expression', V.Init);
|
|
@@ -1582,11 +1612,13 @@ begin
|
|
X:=GetFirstVar;
|
|
X:=GetFirstVar;
|
|
CheckClass(X,TJSVarDeclaration);
|
|
CheckClass(X,TJSVarDeclaration);
|
|
V:=TJSVarDeclaration(X);
|
|
V:=TJSVarDeclaration(X);
|
|
|
|
+ AssertEquals('correct variable type', vtVar, V.VarType);
|
|
// AssertNotNull('Variable statement assigned',(X));
|
|
// AssertNotNull('Variable statement assigned',(X));
|
|
AssertEquals('variable name correct registered', 'a', V.name);
|
|
AssertEquals('variable name correct registered', 'a', V.name);
|
|
X:=GetVars.Nodes[1].Node;
|
|
X:=GetVars.Nodes[1].Node;
|
|
CheckClass(X,TJSVarDeclaration);
|
|
CheckClass(X,TJSVarDeclaration);
|
|
V:=TJSVarDeclaration(X);
|
|
V:=TJSVarDeclaration(X);
|
|
|
|
+ AssertEquals('correct variable type', vtVar, V.VarType);
|
|
AssertEquals('variable name correct registered', 'b', V.Name);
|
|
AssertEquals('variable name correct registered', 'b', V.Name);
|
|
AssertNull('No initialization expression', V.Init);
|
|
AssertNull('No initialization expression', V.Init);
|
|
end;
|
|
end;
|
|
@@ -1608,6 +1640,23 @@ begin
|
|
AssertEquals('Member name identifier correct', 'b', TJSPrimaryExpressionIdent(V.init).Name);
|
|
AssertEquals('Member name identifier correct', 'b', TJSPrimaryExpressionIdent(V.init).Name);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestJSParser.TestConstDeclarationSimpleInit;
|
|
|
|
+Var
|
|
|
|
+ X : TJSELement;
|
|
|
|
+ V : TJSVarDeclaration;
|
|
|
|
+begin
|
|
|
|
+ CreateParser('const a = 1;',MinLetVersion);
|
|
|
|
+ X:=GetFirstVar;
|
|
|
|
+ CheckClass(X,TJSVarDeclaration);
|
|
|
|
+ V:=TJSVarDeclaration(X);
|
|
|
|
+// AssertNotNull('Variable statement assigned',(X));
|
|
|
|
+ AssertEquals('variable name correct registered', 'a', V.Name);
|
|
|
|
+ AssertNotNull('Initialization expression present', V.Init);
|
|
|
|
+ CheckClass(V.Init,TJSLiteral);
|
|
|
|
+ AssertEquals('Expression value type correct', jstNumber,TJSLiteral(V.Init).Value.ValueType);
|
|
|
|
+ AssertEquals('Expression value correct', 1.0, TJSLiteral(V.Init).Value.AsNumber);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestJSParser.TestVarDeclarationDoubleInit;
|
|
procedure TTestJSParser.TestVarDeclarationDoubleInit;
|
|
|
|
|
|
Var
|
|
Var
|