Skip to content

Commit

Permalink
Add test for none
Browse files Browse the repository at this point in the history
  • Loading branch information
DePasqualeOrg committed Oct 1, 2024
1 parent 62be81a commit 32c6714
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tests/LexerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ final class LexerTests: XCTestCase {
"UNDEFINED_VARIABLES": "{{ undefined_variable }}",
"UNDEFINED_ACCESS": "{{ object.undefined_attribute }}",

// Null
"NULL_VARIABLE": "{% if not null_val is defined %}{% set null_val = none %}{% endif %}{% if null_val is not none %}{{ 'fail' }}{% else %}{{ 'pass' }}{% endif %}",

// Ternary operator
"TERNARY_OPERATOR":
"|{{ 'a' if true else 'b' }}|{{ 'a' if false else 'b' }}|{{ 'a' if 1 + 1 == 2 else 'b' }}|{{ 'a' if 1 + 1 == 3 or 1 * 2 == 3 else 'b' }}|",
Expand Down Expand Up @@ -2177,6 +2180,45 @@ final class LexerTests: XCTestCase {
Token(value: "}}", type: .closeExpression),
],

// Null
"NULL_VARIABLE": [
Token(value: "{%", type: .openStatement),
Token(value: "if", type: .if),
Token(value: "not", type: .unaryOperator),
Token(value: "null_val", type: .identifier),
Token(value: "is", type: .is),
Token(value: "defined", type: .identifier),
Token(value: "%}", type: .closeStatement),
Token(value: "{%", type: .openStatement),
Token(value: "set", type: .set),
Token(value: "null_val", type: .identifier),
Token(value: "=", type: .equals),
Token(value: "none", type: .nullLiteral),
Token(value: "%}", type: .closeStatement),
Token(value: "{%", type: .openStatement),
Token(value: "endif", type: .endIf),
Token(value: "%}", type: .closeStatement),
Token(value: "{%", type: .openStatement),
Token(value: "if", type: .if),
Token(value: "null_val", type: .identifier),
Token(value: "is", type: .is),
Token(value: "not", type: .unaryOperator),
Token(value: "none", type: .nullLiteral),
Token(value: "%}", type: .closeStatement),
Token(value: "{{", type: .openExpression),
Token(value: "fail", type: .stringLiteral),
Token(value: "}}", type: .closeExpression),
Token(value: "{%", type: .openStatement),
Token(value: "else", type: .else),
Token(value: "%}", type: .closeStatement),
Token(value: "{{", type: .openExpression),
Token(value: "pass", type: .stringLiteral),
Token(value: "}}", type: .closeExpression),
Token(value: "{%", type: .openStatement),
Token(value: "endif", type: .endIf),
Token(value: "%}", type: .closeStatement),
],

// Ternary operator
"TERNARY_OPERATOR": [
Token(value: "|", type: .text),
Expand Down

0 comments on commit 32c6714

Please sign in to comment.