Skip to content

Commit

Permalink
Underscore support for func tokens + minor regex fixes like bool rege…
Browse files Browse the repository at this point in the history
…x optimization (captures disabled). Lexer unit tests extended. Layout fix - z-index added (higher stack order) due to non-clickable links.
  • Loading branch information
jwaliszko committed Sep 8, 2014
1 parent 24de0be commit df196b9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/ExpressiveAnnotations.MvcWebSample/Content/Site.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
color: #aaa;
font-size: 1.0em;
margin: 0 0 0 -2px;
width: 115px;
}

select {
Expand All @@ -40,10 +41,11 @@ select {

.box-small {
position: relative;
height: 35px;
margin-top: 35px;
width: 65%;
float: right;
font-size: 0.8em;
z-index: 1;
}

.box-small div {
Expand Down
81 changes: 78 additions & 3 deletions src/ExpressiveAnnotations.Tests/LexerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace ExpressiveAnnotations.Tests
{
[TestClass]
public class LexerTest
{
{
[TestMethod]
public void verify_logic()
{
public void verify_complex_expression_analysis()
{
const string expression =
"GoAbroad == true " +
"&& (" +
Expand Down Expand Up @@ -146,5 +146,80 @@ public void verify_logic()
Assert.IsTrue(e.Message == "Invalid token started at: ^");
}
}

[TestMethod]
public void verify_float_token_extraction()
{
AssertToken("1.0", 1.0, TokenType.FLOAT);
AssertToken("-0.3e-2", -0.3e-2, TokenType.FLOAT);

AssertNotToken("1", TokenType.FLOAT);
AssertNotToken("a", TokenType.FLOAT);
}

[TestMethod]
public void verify_string_token_extraction()
{
AssertToken("\"\"", string.Empty, TokenType.STRING);
AssertToken("\"a\"", "a", TokenType.STRING);
AssertToken("\"asd\"", "asd", TokenType.STRING);
AssertToken("\" a s d \"", " a s d ", TokenType.STRING);
AssertToken("''", string.Empty, TokenType.STRING);
AssertToken("'a'", "a", TokenType.STRING);
AssertToken("'asd'", "asd", TokenType.STRING);
AssertToken("' a s d '", " a s d ", TokenType.STRING);

AssertNotToken("a", TokenType.STRING);
}

[TestMethod]
public void verify_func_token_extraction()
{
AssertToken("_", "_", TokenType.FUNC);
AssertToken("__", "__", TokenType.FUNC);
AssertToken("a", "a", TokenType.FUNC);
AssertToken("asd", "asd", TokenType.FUNC);
AssertToken("a_a", "a_a", TokenType.FUNC);
AssertToken("a.a", "a.a", TokenType.FUNC);
AssertToken("_a.a_", "_a.a_", TokenType.FUNC);
AssertToken("A", "A", TokenType.FUNC);
AssertToken("_._", "_._", TokenType.FUNC);
AssertToken("a1", "a1", TokenType.FUNC);
AssertToken("a12.a12", "a12.a12", TokenType.FUNC);
AssertToken("a1.a2.a3", "a1.a2.a3", TokenType.FUNC);
AssertToken("_._._", "_._._", TokenType.FUNC);
AssertToken("_123", "_123", TokenType.FUNC);

AssertNotToken("1", TokenType.FUNC);
AssertNotToken("a..a", TokenType.FUNC);
AssertNotToken("a.1", TokenType.FUNC);
AssertNotToken("a.+", TokenType.FUNC);
}

private static void AssertToken(string expression, object value, TokenType type)
{
var lexer = new Lexer();
var tokens = lexer.Analyze(expression).ToArray();

Assert.AreEqual(tokens.Length, 2);
Assert.AreEqual(tokens[0].Value, value);
Assert.AreEqual(tokens[0].Type, type);
Assert.AreEqual(tokens[1].Type, TokenType.EOF);
}

private static void AssertNotToken(string expression, TokenType type)
{
try
{
var lexer = new Lexer();
var tokens = lexer.Analyze(expression).ToArray();

Assert.IsFalse(tokens.Length == 2 && tokens[0].Type == type);
}
catch (Exception e)
{
Assert.IsTrue(e is InvalidOperationException);
}
}
}
}
4 changes: 2 additions & 2 deletions src/ExpressiveAnnotations/Analysis/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public Lexer()
{TokenType.SUB, @"-"},
{TokenType.MUL, @"\*"},
{TokenType.DIV, @"/"},
{TokenType.BOOL, @"(true|false)"},
{TokenType.BOOL, @"(?:true|false)"},
{TokenType.STRING, @"([""'])(?:\\\1|.)*?\1"},
{TokenType.FUNC, @"[a-zA-Z]+([\.]*[a-zA-Z0-9]*)*"}
{TokenType.FUNC, @"[a-zA-Z_]+(?:(?:\.[a-zA-Z_])?[a-zA-Z0-9_]*)*"}
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/ExpressiveAnnotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.2.1.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]

0 comments on commit df196b9

Please sign in to comment.