[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/tests/JScript .cvsignore,NONE,1.1 Ma
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/tests/JScript .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 TestEngine.cs,NONE,1.1 TestJScript.build,NONE,1.1 TestJScript.cs,NONE,1.1 TestParser.cs,NONE,1.1TestScanner.cs,NONE,1.1 |
Date: |
Mon, 13 Jan 2003 05:53:25 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/tests/JScript
In directory subversions:/tmp/cvs-serv3129/tests/JScript
Added Files:
.cvsignore Makefile.am TestEngine.cs TestJScript.build
TestJScript.cs TestParser.cs TestScanner.cs
Log Message:
Perform the initial check-in of the JScript implementation (requires
treecc 0.2.0 or higher).
--- NEW FILE ---
Makefile
Makefile.in
.deps
*.dll
--- NEW FILE ---
all-local:
"$(CSANT)" $(CSANT_FLAGS) -f TestJScript.build all
CLEANFILES = TestJScript.dll
TESTS = TestJScript.dll
TESTS_ENVIRONMENT = $(SHELL) $(top_builddir)/tools/run_test.sh $(top_builddir)
--- NEW FILE ---
/*
* TestEngine.cs - Tests for the "VsaEngine" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using CSUnit;
using System;
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
public class TestEngine : TestCase
{
// Constructor.
public TestEngine(String name)
: base(name)
{
// Nothing to do here.
}
// Set up for the tests.
protected override void Setup()
{
// Nothing to do here.
}
// Clean up after the tests.
protected override void Cleanup()
{
// Nothing to do here.
}
// Test engine creation.
public void TestEngineCreate()
{
VsaEngine engine;
VsaEngine engine2;
// Create a new engine instance.
engine = VsaEngine.CreateEngine();
AssertNotNull("Create (1)", engine);
AssertEquals("Create (2)", engine,
Globals.contextEngine);
// Try to create another (returns same
instance).
engine2 = VsaEngine.CreateEngine();
AssertEquals("Create (3)", engine, engine2);
// Close the engine.
engine.Close();
AssertNull("Create (4)", Globals.contextEngine);
// Create a new engine, which should be
different this time.
engine = VsaEngine.CreateEngine();
Assert("Create (5)", engine2 != engine);
AssertNotNull("Create (6)", engine);
engine.Close();
}
// Check that a script function object looks correct.
private void CheckScriptFunction(String name, Object obj, int length)
{
Assert("CSF (" + name + ") (1)", obj is
ScriptFunction);
ScriptFunction func = (obj as ScriptFunction);
AssertEquals("CSF (" + name + ") (2)",
"function " + name +
"() {\n" +
" [native code]\n}",
func.ToString());
AssertEquals("CSF (" + name + ") (3)",
length, func.length);
}
// Test the global object properties.
public void TestEngineGlobals()
{
// Create a new engine instance.
VsaEngine engine = VsaEngine.CreateEngine();
// Get the global object.
LenientGlobalObject global =
engine.LenientGlobalObject;
AssertNotNull("Globals (1)", global);
// Check that the "Object" and "Function"
objects
// appear to be of the right form.
Object objectConstructor = global.Object;
AssertNotNull("Globals (2)", objectConstructor);
Assert("Globals (3)", objectConstructor is
ObjectConstructor);
Object functionConstructor = global.Function;
AssertNotNull("Globals (4)",
functionConstructor);
Assert("Globals (5)",
functionConstructor is
FunctionConstructor);
// Check the type information.
AssertSame("Type (1)", typeof(Boolean),
global.boolean);
AssertSame("Type (2)", typeof(Byte),
address@hidden);
AssertSame("Type (3)", typeof(SByte),
address@hidden);
AssertSame("Type (4)", typeof(Char),
address@hidden);
AssertSame("Type (5)", typeof(Int16),
address@hidden);
AssertSame("Type (6)", typeof(UInt16),
address@hidden);
AssertSame("Type (7)", typeof(Int32),
address@hidden);
AssertSame("Type (8)", typeof(UInt32),
address@hidden);
AssertSame("Type (9)", typeof(Int64),
address@hidden);
AssertSame("Type (10)", typeof(UInt64),
address@hidden);
AssertSame("Type (11)", typeof(Single),
address@hidden);
AssertSame("Type (12)", typeof(Double),
address@hidden);
AssertSame("Type (13)", typeof(Decimal),
address@hidden);
AssertSame("Type (14)", typeof(Void),
address@hidden);
// Check the global functions.
CheckScriptFunction("CollectGarbage",
global.CollectGarbage, 0);
CheckScriptFunction("decodeURI",
global.decodeURI, 1);
CheckScriptFunction("decodeURIComponent",
global.decodeURIComponent, 1);
CheckScriptFunction("encodeURI",
global.encodeURI, 1);
CheckScriptFunction("encodeURIComponent",
global.encodeURIComponent, 1);
CheckScriptFunction("escape",
global.escape, 1);
CheckScriptFunction("eval",
global.eval, 1);
CheckScriptFunction("isFinite",
global.isFinite, 1);
CheckScriptFunction("isNaN",
global.isNaN, 1);
CheckScriptFunction("parseFloat",
global.parseFloat, 1);
CheckScriptFunction("parseInt",
global.parseInt, 2);
CheckScriptFunction("ScriptEngine",
global.ScriptEngine, 0);
CheckScriptFunction("ScriptEngineBuildVersion",
global.ScriptEngineBuildVersion, 0);
CheckScriptFunction("ScriptEngineMajorVersion",
global.ScriptEngineMajorVersion, 0);
CheckScriptFunction("ScriptEngineMinorVersion",
global.ScriptEngineMinorVersion, 0);
CheckScriptFunction("unescape",
global.unescape, 1);
// Check the global values.
Assert("Value (1)",
Double.IsPositiveInfinity((double)(global.Infinity)));
Assert("Value (2)",
Double.IsNaN((double)(global.NaN)));
AssertNull("Value (3)", global.undefined);
// Close the engine and exit.
engine.Close();
}
}; // class TestEngine
--- NEW FILE ---
<?xml version="1.0"?>
<project name="pnetlib TestJScript" default="all">
<target name="all">
<!-- Build the TestJScript.dll library -->
<compile output="TestJScript.dll"
target="library"
unsafe="true"
debug="true"
nostdlib="true"
optimize="true">
<sources>
<includes name="**/*.cs"/>
</sources>
<references>
<file name="../../csunit/cstest.dll"/>
<file name="../../JScript/JScript.Test.dll"/>
<file name="../../compat/Microsoft.Vsa.dll"/>
<file name="../../System/System.dll"/>
<file name="../../runtime/mscorlib.dll"/>
</references>
<arg compiler="cscc" value="-Wno-empty-input"/>
<arg compiler="csc" value="/nowarn:626"/>
<arg compiler="csc" value="/nowarn:649"/>
<arg compiler="csc" value="/nowarn:168"/>
<arg compiler="csc" value="/nowarn:67"/>
<arg compiler="csc" value="/nowarn:169"/>
</compile>
</target>
</project>
--- NEW FILE ---
/*
* TestJScript.cs - Tests for the JScript implementation
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using CSUnit;
using System;
public class TestJScript
{
public static TestSuite Suite()
{
TestSuite fullSuite, suite;
fullSuite = new TestSuite("JScript Tests");
suite = new TestSuite("Parser Tests");
suite.AddTests(typeof(TestScanner));
suite.AddTests(typeof(TestParser));
fullSuite.AddTest(suite);
suite = new TestSuite("Engine Tests");
suite.AddTests(typeof(TestEngine));
fullSuite.AddTest(suite);
return fullSuite;
}
}; // class TestJScript
--- NEW FILE ---
/*
* TestParser.cs - Tests for the "JSParser" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using CSUnit;
using System;
using Microsoft.JScript;
public class TestParser : TestCase
{
// Constructor.
public TestParser(String name)
: base(name)
{
// Nothing to do here.
}
// Set up for the tests.
protected override void Setup()
{
// Nothing to do here.
}
// Clean up after the tests.
protected override void Cleanup()
{
// Nothing to do here.
}
// Test parser creation.
public void TestParserCreate()
{
JSParser parser =
JSParserTest.TestCreateParser("");
AssertNotNull("Create (1)", parser);
AssertNotNull("Create (2)", parser.Parse());
parser = JSParserTest.TestCreateParser("");
AssertNotNull("Create (3)", parser);
AssertNotNull("Create (4)",
parser.ParseEvalBody());
}
// Test a simple parse to see if the JNode tree is created correctly.
public void TestParserSimple()
{
JSParser parser =
JSParserTest.TestCreateParser("x = 3");
Block block = parser.ParseEvalBody();
Object jnode = JSParserTest.TestJNodeGet(block);
// Top-level jnode should be JBlock.
AssertEquals("Simple (1)", "JBlock",
JSParserTest.TestJNodeGetKind(jnode));
// Should have a single expression statement.
Object statements =
JSParserTest.TestJNodeGetField(jnode,
"statements");
AssertEquals("Simple (2)", "JExprStmt",
JSParserTest.TestJNodeGetKind(statements));
// The expression statement should contain an
assignment.
Object assign =
JSParserTest.TestJNodeGetField(statements, "expr");
AssertEquals("Simple (3)", "JAssign",
JSParserTest.TestJNodeGetKind(assign));
// Left-hand side should be the identifier "x".
Object lhs =
JSParserTest.TestJNodeGetField(assign,
"expr1");
AssertEquals("Simple (4)", "JIdentifier",
JSParserTest.TestJNodeGetKind(lhs));
AssertEquals("Simple (5)", "x",
JSParserTest.TestJNodeGetField(lhs, "name"));
// Right-hand side should be the integer 3.
Object rhs =
JSParserTest.TestJNodeGetField(assign,
"expr2");
AssertEquals("Simple (6)", "JConstant",
JSParserTest.TestJNodeGetKind(rhs));
Object value =
JSParserTest.TestJNodeGetField(rhs,
"value");
Assert("Simple (7)", (value is Int32));
AssertEquals("Simple (7)", 3, (int)value);
}
// Parse an eval statement and check for success.
private static void Yes(String tag, String source)
{
// Parse the source.
JSParser parser =
JSParserTest.TestCreateParser(source);
Block block = parser.ParseEvalBody();
Object jnode = JSParserTest.TestJNodeGet(block);
// Determine the location of the source end.
int posn = 0;
int line = 1;
int temp;
int endColumn = source.Length;
while(posn < source.Length)
{
temp = source.IndexOf('\n', posn);
if(temp == -1)
{
endColumn = source.Length -
posn;
break;
}
++line;
posn = temp + 1;
}
// Check that the full node's context is
appropriate.
Context context =
JSParserTest.TestJNodeGetContext(jnode);
AssertEquals(tag + " [1]", 0,
context.StartColumn);
AssertEquals(tag + " [2]", 1,
context.StartLine);
AssertEquals(tag + " [3]", 0,
context.StartPosition);
AssertEquals(tag + " [4]", endColumn,
context.EndColumn);
AssertEquals(tag + " [5]", line,
context.EndLine);
AssertEquals(tag + " [6]", source.Length,
context.EndPosition);
AssertEquals(tag + " [7]", source,
context.GetCode());
}
// Parse an eval statement and check for failure.
private static void No(String tag, String source)
{
try
{
JSParser parser =
JSParserTest.TestCreateParser(source);
Block block = parser.ParseEvalBody();
Fail(tag + " [1]");
}
catch(JScriptException e)
{
AssertEquals(tag + "[2]",
((int)(JSError.SyntaxError)) +
unchecked((int)0x800A0000),
e.ErrorNumber);
}
}
// Test various successful parses.
public void TestParserSuccess()
{
Yes("Success (1)", "2 + 2");
Yes("Success (2)", "2 +\n2");
Yes("Success (3)", "{ var x = 3 }");
Yes("Success (4)", ";;;;;;;;;;");
}
// Test various unsuccessful parses.
public void TestParserFail()
{
No("Fail (1)", "+");
}
}; // class TestParser
--- NEW FILE ---
/*
* TestScanner.cs - Tests for the "JSScanner" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using CSUnit;
using System;
using Microsoft.JScript;
public class TestScanner : TestCase
{
// Constructor.
public TestScanner(String name)
: base(name)
{
// Nothing to do here.
}
// Set up for the tests.
protected override void Setup()
{
// Nothing to do here.
}
// Clean up after the tests.
protected override void Cleanup()
{
// Nothing to do here.
}
// Test scanner creation.
public void TestScannerCreate()
{
JSScanner scanner;
Context token;
scanner = JSScannerTest.TestCreateScanner("//
comment\n");
scanner.GetNextToken();
token =
JSScannerTest.TestGetTokenContext(scanner);
AssertEquals("Create (1)", JSToken.EndOfFile,
token.GetToken());
}
// Test keyword recognition.
public void TestScannerKeywords()
{
JSScanner scanner;
Context token;
scanner = JSScannerTest.TestCreateScanner
("hello get switch assert \\assert
switch0");
scanner.GetNextToken();
token =
JSScannerTest.TestGetTokenContext(scanner);
AssertEquals("Keywords (1)", JSToken.Identifier,
token.GetToken());
AssertEquals("Keywords (2)", "hello",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Keywords (3)", JSToken.Get,
token.GetToken());
AssertNull("Keywords (4)",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Keywords (5)", JSToken.Switch,
token.GetToken());
AssertNull("Keywords (6)",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Keywords (7)", JSToken.Assert,
token.GetToken());
AssertNull("Keywords (8)",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Keywords (9)", JSToken.Identifier,
token.GetToken());
AssertEquals("Keywords (10)", "assert",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Keywords (11)",
JSToken.Identifier,
token.GetToken());
AssertEquals("Keywords (12)", "switch0",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Keywords (13)",
JSToken.EndOfFile,
token.GetToken());
}
// Test comment recognition.
public void TestScannerComments()
{
JSScanner scanner;
Context token;
scanner = JSScannerTest.TestCreateScanner
("#!/usr/local/bin/ilrun\n" +
"hello// single-line comment\r" +
"/* multi-line 1 */ switch /*
multi-line\r\n" +
"2 */ assert /= / /*");
scanner.GetNextToken();
token =
JSScannerTest.TestGetTokenContext(scanner);
AssertEquals("Comments (1)", JSToken.Identifier,
token.GetToken());
AssertEquals("Comments (2)", "hello",
JSScannerTest.TestGetIdentifierName(scanner));
AssertEquals("Comments (3)", 2,
token.StartLine);
AssertEquals("Comments (4)", 2, token.EndLine);
AssertEquals("Comments (5)", 23,
token.StartPosition);
AssertEquals("Comments (6)", 28,
token.EndPosition);
AssertEquals("Comments (7)", 0,
token.StartColumn);
AssertEquals("Comments (8)", 5,
token.EndColumn);
scanner.GetNextToken();
AssertEquals("Comments (9)", JSToken.Switch,
token.GetToken());
AssertNull("Comments (10)",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Comments (11)", JSToken.Assert,
token.GetToken());
AssertNull("Comments (12)",
JSScannerTest.TestGetIdentifierName(scanner));
AssertEquals("Comments (13)", 4,
token.StartLine);
AssertEquals("Comments (14)", 4, token.EndLine);
scanner.GetNextToken();
AssertEquals("Comments (15)",
JSToken.DivideAssign,
token.GetToken());
AssertNull("Comments (16)",
JSScannerTest.TestGetIdentifierName(scanner));
scanner.GetNextToken();
AssertEquals("Comments (17)", JSToken.Divide,
token.GetToken());
AssertNull("Comments (18)",
JSScannerTest.TestGetIdentifierName(scanner));
try
{
scanner.GetNextToken();
Fail("Comments (19)");
}
catch(Exception e)
{
AssertEquals("Comments (20)",
JSError.NoCommentEnd,
JSScannerTest.TestExtractError(e));
AssertEquals("Comments (21)",
JSToken.UnterminatedComment,
token.GetToken());
}
}
// Test a single operator.
private void TestOp(JSScanner scanner, String ops,
ref int posn, JSToken expected)
{
Context token =
JSScannerTest.TestGetTokenContext(scanner);
scanner.GetNextToken();
int next = ops.IndexOf(' ', posn);
String thisop = ops.Substring(posn, next -
posn);
AssertEquals("TestOp[" + thisop + "] (1)",
expected,
token.GetToken());
AssertEquals("TestOp[" + thisop + "] (2)",
thisop,
token.GetCode());
AssertEquals("TestOp[" + thisop + "] (3)",
posn,
token.StartPosition);
AssertEquals("TestOp[" + thisop + "] (4)",
next,
token.EndPosition);
posn = next + 1;
}
// Test operator recognition.
public void TestScannerOperators()
{
JSScanner scanner;
String ops = "{ } ( ) [ ] . ; , < > <= >= == !=
" +
"=== !== + - * / % ++
-- << >> >>> " +
"& | ^ ! ~ && || ? : =
+= -= *= /= " +
"%= <<= >>= >>>= &= |=
^= :: ";
int posn = 0;
scanner = JSScannerTest.TestCreateScanner(ops);
TestOp(scanner, ops, ref posn,
JSToken.LeftCurly);
TestOp(scanner, ops, ref posn,
JSToken.RightCurly);
TestOp(scanner, ops, ref posn,
JSToken.LeftParen);
TestOp(scanner, ops, ref posn,
JSToken.RightParen);
TestOp(scanner, ops, ref posn,
JSToken.LeftBracket);
TestOp(scanner, ops, ref posn,
JSToken.RightBracket);
TestOp(scanner, ops, ref posn,
JSToken.AccessField);
TestOp(scanner, ops, ref posn,
JSToken.Semicolon);
TestOp(scanner, ops, ref posn, JSToken.Comma);
TestOp(scanner, ops, ref posn,
JSToken.LessThan);
TestOp(scanner, ops, ref posn,
JSToken.GreaterThan);
TestOp(scanner, ops, ref posn,
JSToken.LessThanEqual);
TestOp(scanner, ops, ref posn,
JSToken.GreaterThanEqual);
TestOp(scanner, ops, ref posn, JSToken.Equal);
TestOp(scanner, ops, ref posn,
JSToken.NotEqual);
TestOp(scanner, ops, ref posn,
JSToken.StrictEqual);
TestOp(scanner, ops, ref posn,
JSToken.StrictNotEqual);
TestOp(scanner, ops, ref posn, JSToken.Plus);
TestOp(scanner, ops, ref posn, JSToken.Minus);
TestOp(scanner, ops, ref posn,
JSToken.Multiply);
TestOp(scanner, ops, ref posn, JSToken.Divide);
TestOp(scanner, ops, ref posn, JSToken.Modulo);
TestOp(scanner, ops, ref posn,
JSToken.Increment);
TestOp(scanner, ops, ref posn,
JSToken.Decrement);
TestOp(scanner, ops, ref posn,
JSToken.LeftShift);
TestOp(scanner, ops, ref posn,
JSToken.RightShift);
TestOp(scanner, ops, ref posn,
JSToken.UnsignedRightShift);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseAnd);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseOr);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseXor);
TestOp(scanner, ops, ref posn,
JSToken.LogicalNot);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseNot);
TestOp(scanner, ops, ref posn,
JSToken.LogicalAnd);
TestOp(scanner, ops, ref posn,
JSToken.LogicalOr);
TestOp(scanner, ops, ref posn,
JSToken.ConditionalIf);
TestOp(scanner, ops, ref posn, JSToken.Colon);
TestOp(scanner, ops, ref posn, JSToken.Assign);
TestOp(scanner, ops, ref posn,
JSToken.PlusAssign);
TestOp(scanner, ops, ref posn,
JSToken.MinusAssign);
TestOp(scanner, ops, ref posn,
JSToken.MultiplyAssign);
TestOp(scanner, ops, ref posn,
JSToken.DivideAssign);
TestOp(scanner, ops, ref posn,
JSToken.ModuloAssign);
TestOp(scanner, ops, ref posn,
JSToken.LeftShiftAssign);
TestOp(scanner, ops, ref posn,
JSToken.RightShiftAssign);
TestOp(scanner, ops, ref posn,
JSToken.UnsignedRightShiftAssign);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseAndAssign);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseOrAssign);
TestOp(scanner, ops, ref posn,
JSToken.BitwiseXorAssign);
TestOp(scanner, ops, ref posn,
JSToken.DoubleColon);
}
// Parse a number.
private void TestNum(String value, JSToken expected)
{
JSScanner scanner;
Context token;
scanner =
JSScannerTest.TestCreateScanner(value);
token =
JSScannerTest.TestGetTokenContext(scanner);
scanner.GetNextToken();
AssertEquals("TestNum[" + value + "] (1)",
value,
token.GetCode());
AssertEquals("TestNum[" + value + "] (2)",
expected,
token.GetToken());
}
// Parse an invalid number.
private void TestInvalidNum(String value, JSError expected)
{
JSScanner scanner;
Context token;
scanner =
JSScannerTest.TestCreateScanner(value);
token =
JSScannerTest.TestGetTokenContext(scanner);
try
{
scanner.GetNextToken();
Fail("TestInvalidNum[" + value + "]
(1)");
}
catch(Exception e)
{
AssertEquals("TestNum[" + value + "]
(2)", expected,
JSScannerTest.TestExtractError(e));
}
}
// Test number recognition.
public void TestScannerNumbers()
{
TestNum("0", JSToken.IntegerLiteral);
TestNum("0x17a", JSToken.IntegerLiteral);
TestNum("0X17A", JSToken.IntegerLiteral);
TestNum("123", JSToken.IntegerLiteral);
TestNum("123.0", JSToken.NumericLiteral);
TestNum(".123", JSToken.NumericLiteral);
TestNum("1e123", JSToken.NumericLiteral);
TestNum("1E-123", JSToken.NumericLiteral);
TestNum("1.5E-123", JSToken.NumericLiteral);
TestNum(".5E+123", JSToken.NumericLiteral);
TestInvalidNum("0x", JSError.BadHexDigit);
TestInvalidNum("0xG", JSError.BadHexDigit);
}
}; // class TestScanner
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/tests/JScript .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 TestEngine.cs,NONE,1.1 TestJScript.build,NONE,1.1 TestJScript.cs,NONE,1.1 TestParser.cs,NONE,1.1TestScanner.cs,NONE,1.1,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/tests Makefile.am,1.3,1.4
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/doc JScript-embed.txt,NONE,1.1 JScript-internals.txt,NONE,1.1
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/tests Makefile.am,1.3,1.4
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/doc JScript-embed.txt,NONE,1.1 JScript-internals.txt,NONE,1.1
- Index(es):