Create lexer and template

This commit is contained in:
Kyle Fuller
2014-10-24 14:25:53 +01:00
parent bf67ea3e5f
commit 652a4f9c88
7 changed files with 110 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
//
// LexerTests.swift
// Stencil
//
// Created by Kyle Fuller on 24/10/2014.
// Copyright (c) 2014 Cocode. All rights reserved.
//
import Cocoa
import XCTest
import Stencil
class LexerTests: XCTestCase {
func testTokenizeText() {
let lexer = Lexer(templateString:"Hello World")
let tokens = lexer.tokenize()
XCTAssertEqual(tokens.count, 1)
XCTAssertEqual(tokens.first!, Token.Text(value: "Hello World"))
}
}

View File

@@ -62,7 +62,7 @@ class VariableNodeTests: NodeTests {
class RenderNodeTests: NodeTests {
func testRenderingNodes() {
let nodes = [TextNode(text:"Hello "), VariableNode(variable: "name")] as [Node]
let (result:String?, error:Error?) = render(nodes, context)
let (result:String?, error:Error?) = renderNodes(nodes, context)
XCTAssertEqual(result!, "Hello Kyle")
XCTAssertTrue(error == nil)
@@ -70,7 +70,7 @@ class RenderNodeTests: NodeTests {
func testRenderingNodesWithFailure() {
let nodes = [TextNode(text:"Hello "), VariableNode(variable: "name"), ErrorNode()] as [Node]
let (result:String?, error:Error?) = render(nodes, context)
let (result:String?, error:Error?) = renderNodes(nodes, context)
XCTAssertEqual(error!.description, "Node Error")
XCTAssertTrue(result == nil)

View File

@@ -0,0 +1,23 @@
//
// TemplateTests.swift
// Stencil
//
// Created by Kyle Fuller on 23/10/2014.
// Copyright (c) 2014 Cocode. All rights reserved.
//
import Cocoa
import XCTest
import Stencil
class TemplateTests: XCTestCase {
func testTemplate() {
let context = Context(dictionary: [ "name": "Kyle" ])
let template = Template(templateString: "Hello World")
let (string, error) = template.render(context)
XCTAssertEqual(string!, "Hello World")
XCTAssertTrue(error == nil)
}
}