Use spectre-build for tests
This commit is contained in:
@@ -1 +1 @@
|
||||
2.2-dev
|
||||
DEVELOPMENT-SNAPSHOT-2016-01-25-a
|
||||
|
||||
8
.travis.yml
Normal file
8
.travis.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
os:
|
||||
- osx
|
||||
osx_image: xcode7.2
|
||||
install:
|
||||
- curl -sL https://gist.github.com/kylef/5c0475ff02b7c7671d2a/raw/621ef9b29bbb852fdfd2e10ed147b321d792c1e4/swiftenv-install.sh | bash
|
||||
script:
|
||||
- . ~/.swiftenv/init
|
||||
- make test
|
||||
7
Makefile
Normal file
7
Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
stencil:
|
||||
@echo "Building Stencil"
|
||||
@swift build
|
||||
|
||||
test: stencil
|
||||
@echo "Running Tests"
|
||||
@.build/debug/spectre-build
|
||||
@@ -4,5 +4,8 @@ let package = Package(
|
||||
name: "Stencil",
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/kylef/PathKit.git", majorVersion: 0, minor: 6),
|
||||
],
|
||||
testDependencies: [
|
||||
.Package(url: "https://github.com/kylef/spectre-build", majorVersion: 0),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Stencil
|
||||
|
||||
[](https://circleci.com/gh/kylef/Stencil)
|
||||
[](https://travis-ci.org/kylef/Stencil)
|
||||
|
||||
Stencil is a simple and powerful template language for Swift. It provides a
|
||||
syntax similar to Django and Mustache. If you're familiar with these, you will
|
||||
|
||||
@@ -2,7 +2,8 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("Context") {
|
||||
func testContext() {
|
||||
describe("Context") {
|
||||
var context: Context!
|
||||
|
||||
$0.before {
|
||||
@@ -62,4 +63,5 @@ describe("Context") {
|
||||
try expect(didRun).to.beTrue()
|
||||
try expect(context["name"] as? String) == "Kyle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("template filters") {
|
||||
func testFilter() {
|
||||
describe("template filters") {
|
||||
let context = Context(dictionary: ["name": "Kyle"])
|
||||
|
||||
$0.it("allows you to register a custom filter") {
|
||||
@@ -21,7 +22,7 @@ describe("template filters") {
|
||||
try expect(result) == "Kyle Kyle"
|
||||
}
|
||||
|
||||
$0.it("allows you to register a custom filter") {
|
||||
$0.it("allows you to register a custom which throws") {
|
||||
let template = Template(templateString: "{{ name|repeat }}")
|
||||
let namespace = Namespace()
|
||||
namespace.registerFilter("repeat") { value in
|
||||
@@ -36,34 +37,34 @@ describe("template filters") {
|
||||
let result = try template.render(Context(dictionary: ["name": "kyle"]))
|
||||
try expect(result) == "KYLE"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("capitalize filter") {
|
||||
describe("capitalize filter") {
|
||||
let template = Template(templateString: "{{ name|capitalize }}")
|
||||
|
||||
$0.it("capitalizes a string") {
|
||||
let result = try template.render(Context(dictionary: ["name": "kyle"]))
|
||||
try expect(result) == "Kyle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("uppercase filter") {
|
||||
describe("uppercase filter") {
|
||||
let template = Template(templateString: "{{ name|uppercase }}")
|
||||
|
||||
$0.it("transforms a string to be uppercase") {
|
||||
let result = try template.render(Context(dictionary: ["name": "kyle"]))
|
||||
try expect(result) == "KYLE"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe("lowercase filter") {
|
||||
describe("lowercase filter") {
|
||||
let template = Template(templateString: "{{ name|lowercase }}")
|
||||
|
||||
$0.it("transforms a string to be lowercase") {
|
||||
let result = try template.render(Context(dictionary: ["name": "Kyle"]))
|
||||
try expect(result) == "kyle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("Lexer") {
|
||||
func testLexer() {
|
||||
describe("Lexer") {
|
||||
$0.it("can tokenize text") {
|
||||
let lexer = Lexer(templateString: "Hello World")
|
||||
let tokens = lexer.tokenize()
|
||||
@@ -45,4 +46,5 @@ describe("Lexer") {
|
||||
try expect(tokens[0]) == Token.Variable(value: "thing")
|
||||
try expect(tokens[1]) == Token.Variable(value: "name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import Stencil
|
||||
import Foundation
|
||||
|
||||
|
||||
describe("ForNode") {
|
||||
func testForNode() {
|
||||
describe("ForNode") {
|
||||
let context = Context(dictionary: [
|
||||
"items": [1, 2, 3],
|
||||
"emptyItems": [Int](),
|
||||
@@ -59,4 +60,5 @@ describe("ForNode") {
|
||||
let node = ForNode(variable: "items", loopVariable: "item", nodes: nodes, emptyNodes: [])
|
||||
try expect(try node.render(context)) == "112233"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import Spectre
|
||||
import Stencil
|
||||
|
||||
describe("IfNode") {
|
||||
|
||||
func testIfNode() {
|
||||
describe("IfNode") {
|
||||
$0.describe("parsing") {
|
||||
$0.it("can parse an if block") {
|
||||
let tokens = [
|
||||
@@ -110,4 +112,5 @@ describe("IfNode") {
|
||||
try expect(try node.render(arrayContext)) == "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ class ErrorNode : NodeType {
|
||||
}
|
||||
|
||||
|
||||
describe("Node") {
|
||||
func testNode() {
|
||||
describe("Node") {
|
||||
let context = Context(dictionary: [
|
||||
"name": "Kyle",
|
||||
"age": 27,
|
||||
@@ -55,4 +56,5 @@ describe("Node") {
|
||||
try expect(try renderNodes(nodes, context)).toThrow(TemplateSyntaxError("Custom Error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("NowNode") {
|
||||
func testNowNode() {
|
||||
describe("NowNode") {
|
||||
$0.describe("parsing") {
|
||||
$0.it("parses default format without any now arguments") {
|
||||
let tokens = [ Token.Block(value: "now") ]
|
||||
@@ -36,4 +37,5 @@ describe("NowNode") {
|
||||
try expect(try node.render(Context())) == date
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("TokenParser") {
|
||||
func testTokenParser() {
|
||||
describe("TokenParser") {
|
||||
$0.it("can parse a text token") {
|
||||
let parser = TokenParser(tokens: [
|
||||
Token.Text(value: "Hello World")
|
||||
@@ -52,4 +53,5 @@ describe("TokenParser") {
|
||||
|
||||
try expect(try parser.parse()).toThrow(TemplateSyntaxError("Unknown template tag 'unknown'"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ class CustomNode : NodeType {
|
||||
}
|
||||
|
||||
|
||||
describe("Stencil") {
|
||||
func testStencil() {
|
||||
describe("Stencil") {
|
||||
$0.it("can render the README example") {
|
||||
let templateString = "There are {{ articles.count }} articles.\n" +
|
||||
"\n" +
|
||||
@@ -24,7 +25,7 @@ describe("Stencil") {
|
||||
]
|
||||
])
|
||||
|
||||
let template = Template(templateString:templateString)
|
||||
let template = Template(templateString: templateString)
|
||||
let result = try template.render(context)
|
||||
|
||||
let fixture = "There are 2 articles.\n" +
|
||||
@@ -60,4 +61,5 @@ describe("Stencil") {
|
||||
|
||||
try expect(try template.render(namespace: namespace)) == "Hello World"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import Stencil
|
||||
import PathKit
|
||||
|
||||
|
||||
describe("Include") {
|
||||
let path = Path(__FILE__) + ".." + ".." + "Tests" + "fixtures"
|
||||
func testInclude() {
|
||||
describe("Include") {
|
||||
let path = Path(__FILE__) + ".." + ".." + "fixtures"
|
||||
let loader = TemplateLoader(paths: [path])
|
||||
|
||||
$0.describe("parsing") {
|
||||
@@ -55,4 +56,5 @@ describe("Include") {
|
||||
try expect(value) == "Hello World!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import Stencil
|
||||
import PathKit
|
||||
|
||||
|
||||
describe("Inheritence") {
|
||||
let path = Path(__FILE__) + ".." + ".." + "Tests" + "fixtures"
|
||||
func testInheritence() {
|
||||
describe("Inheritence") {
|
||||
let path = Path(__FILE__) + ".." + ".." + "fixtures"
|
||||
let loader = TemplateLoader(paths: [path])
|
||||
|
||||
$0.it("can inherit from another template") {
|
||||
@@ -12,4 +13,5 @@ describe("Inheritence") {
|
||||
let template = loader.loadTemplate("child.html")
|
||||
try expect(try template?.render(context)) == "Header\nChild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ import Stencil
|
||||
import PathKit
|
||||
|
||||
|
||||
describe("TemplateLoader") {
|
||||
func testTemplateLoader() {
|
||||
describe("TemplateLoader") {
|
||||
let path = Path(__FILE__) + ".." + ".." + "Tests" + "fixtures"
|
||||
let loader = TemplateLoader(paths: [path])
|
||||
|
||||
@@ -20,4 +21,5 @@ describe("TemplateLoader") {
|
||||
throw failure("didn't find the template")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("Template") {
|
||||
func testTemplate() {
|
||||
describe("Template") {
|
||||
$0.it("can render a template from a string") {
|
||||
let context = Context(dictionary: [ "name": "Kyle" ])
|
||||
let template = Template(templateString: "Hello World")
|
||||
let result = try template.render(context)
|
||||
try expect(result) == "Hello World"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import Spectre
|
||||
import Stencil
|
||||
|
||||
|
||||
describe("Token") {
|
||||
func testToken() {
|
||||
describe("Token") {
|
||||
$0.it("can split the contents into components") {
|
||||
let token = Token.Text(value: "hello world")
|
||||
let components = token.components()
|
||||
@@ -29,4 +30,5 @@ describe("Token") {
|
||||
try expect(components[0]) == "hello"
|
||||
try expect(components[1]) == "\"kyle fuller\""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ import Stencil
|
||||
}
|
||||
|
||||
|
||||
describe("Variable") {
|
||||
func testVariable() {
|
||||
describe("Variable") {
|
||||
let context = Context(dictionary: [
|
||||
"name": "Kyle",
|
||||
"contacts": ["Katie", "Carlton"],
|
||||
@@ -65,4 +66,5 @@ describe("Variable") {
|
||||
let result = try variable.resolve(context) as? String
|
||||
try expect(result) == "Hello World"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
Tests/main.swift
Normal file
15
Tests/main.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
testContext()
|
||||
testFilter()
|
||||
testLexer()
|
||||
testToken()
|
||||
testTokenParser()
|
||||
testTemplateLoader()
|
||||
testTemplate()
|
||||
testVariable()
|
||||
testNode()
|
||||
testForNode()
|
||||
testIfNode()
|
||||
testNowNode()
|
||||
testInclude()
|
||||
testInheritence()
|
||||
testStencil()
|
||||
21
circle.yml
21
circle.yml
@@ -1,21 +0,0 @@
|
||||
machine:
|
||||
xcode:
|
||||
version: "7.0"
|
||||
environment:
|
||||
XCODE_SCHEME: NONE
|
||||
XCODE_PROJECT: NONE
|
||||
|
||||
dependencies:
|
||||
post:
|
||||
- brew install --HEAD kylef/formulae/conche
|
||||
|
||||
test:
|
||||
override:
|
||||
- conche test
|
||||
|
||||
deployment:
|
||||
release:
|
||||
tag: /.*/
|
||||
commands:
|
||||
- pod trunk push
|
||||
|
||||
Reference in New Issue
Block a user