Skip to content

Commit

Permalink
Update to Spectre 0.9.0 (#247)
Browse files Browse the repository at this point in the history
* update to Spectre 0.9.0

* fix variable spec tests

* fix flatMap warning

* updated CHANGELOG
  • Loading branch information
ilyapuchka authored Sep 23, 2018
1 parent d238c25 commit f7bda22
Show file tree
Hide file tree
Showing 26 changed files with 2,190 additions and 2,018 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.conche/
.build/
Packages/
Package.resolved
Package.pins
*.xcodeproj
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
- Now you can conditionally render variables with `{{ variable if condition }}`, which is a shorthand for `{% if condition %}{{ variable }}{% endif %}`. You can also use `else` like `{{ variable1 if condition else variable2 }}`, which is a shorthand for `{% if condition %}{{ variable1 }}{% else %}{{ variable2 }}{% endif %}`
[Ilya Puchka](https://github.com/ilyapuchka)
[#243](https://github.com/stencilproject/Stencil/pull/243)

- Now you can access string characters by index or get string length the same was as if it was an array, i.e. `{{ 'string'.first }}`, `{{ 'string'.last }}`, `{{ 'string'.1 }}`, `{{ 'string'.count }}`.
[Ilya Puchka](https://github.com/ilyapuchka)
[#245](https://github.com/stencilproject/Stencil/pull/245)
Expand All @@ -35,6 +34,9 @@
- Updated the codebase to use Swift 4 features.
[David Jennes](https://github.com/djbe)
[#239](https://github.com/stencilproject/Stencil/pull/239)
- Update to Spectre 0.9.0.
[Ilya Puchka](https://github.com/ilyapuchka)
[#247](https://github.com/stencilproject/Stencil/pull/247)


## 0.12.1
Expand Down
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
"version": "0.9.2"
}
},
{
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
}
]
},
"version": 1
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/kylef/PathKit.git", from: "0.9.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.8.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.0"),
],
targets: [
.target(name: "Stencil", dependencies: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/IfTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final class IfExpressionParser {
private init(components: ArraySlice<String>, tokenParser: TokenParser, token: Token) throws {
var parsedComponents = Set<Int>()
var bracketsBalance = 0
self.tokens = try zip(components.indices, components).flatMap { (index, component) in
self.tokens = try zip(components.indices, components).compactMap { (index, component) in
guard !parsedComponents.contains(index) else { return nil }

if component == "(" {
Expand Down
7 changes: 6 additions & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import XCTest

import StencilTests

stencilTests()
var tests = [XCTestCaseEntry]()
tests += StencilTests.__allTests()

XCTMain(tests)
108 changes: 56 additions & 52 deletions Tests/StencilTests/ContextSpec.swift
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
import XCTest
import Spectre
@testable import Stencil


func testContext() {
describe("Context") {
var context: Context!
class ContextTests: XCTestCase {

func testContext() {
describe("Context") {
var context: Context!

$0.before {
context = Context(dictionary: ["name": "Kyle"])
}
$0.before {
context = Context(dictionary: ["name": "Kyle"])
}

$0.it("allows you to get a value via subscripting") {
try expect(context["name"] as? String) == "Kyle"
}
$0.it("allows you to get a value via subscripting") {
try expect(context["name"] as? String) == "Kyle"
}

$0.it("allows you to set a value via subscripting") {
context["name"] = "Katie"
$0.it("allows you to set a value via subscripting") {
context["name"] = "Katie"

try expect(context["name"] as? String) == "Katie"
}
try expect(context["name"] as? String) == "Katie"
}

$0.it("allows you to remove a value via subscripting") {
context["name"] = nil
$0.it("allows you to remove a value via subscripting") {
context["name"] = nil

try expect(context["name"]).to.beNil()
}
try expect(context["name"]).to.beNil()
}

$0.it("allows you to retrieve a value from a parent") {
try context.push {
try expect(context["name"] as? String) == "Kyle"
$0.it("allows you to retrieve a value from a parent") {
try context.push {
try expect(context["name"] as? String) == "Kyle"
}
}
}

$0.it("allows you to override a parent's value") {
try context.push {
context["name"] = "Katie"
try expect(context["name"] as? String) == "Katie"
$0.it("allows you to override a parent's value") {
try context.push {
context["name"] = "Katie"
try expect(context["name"] as? String) == "Katie"
}
}
}

$0.it("allows you to pop to restore previous state") {
context.push {
context["name"] = "Katie"
$0.it("allows you to pop to restore previous state") {
context.push {
context["name"] = "Katie"
}

try expect(context["name"] as? String) == "Kyle"
}

try expect(context["name"] as? String) == "Kyle"
}
$0.it("allows you to remove a parent's value in a level") {
try context.push {
context["name"] = nil
try expect(context["name"]).to.beNil()
}

$0.it("allows you to remove a parent's value in a level") {
try context.push {
context["name"] = nil
try expect(context["name"]).to.beNil()
try expect(context["name"] as? String) == "Kyle"
}

try expect(context["name"] as? String) == "Kyle"
}
$0.it("allows you to push a dictionary and run a closure then restoring previous state") {
var didRun = false

$0.it("allows you to push a dictionary and run a closure then restoring previous state") {
var didRun = false
try context.push(dictionary: ["name": "Katie"]) {
didRun = true
try expect(context["name"] as? String) == "Katie"
}

try context.push(dictionary: ["name": "Katie"]) {
didRun = true
try expect(context["name"] as? String) == "Katie"
try expect(didRun).to.beTrue()
try expect(context["name"] as? String) == "Kyle"
}

try expect(didRun).to.beTrue()
try expect(context["name"] as? String) == "Kyle"
}

$0.it("allows you to flatten the context contents") {
try context.push(dictionary: ["test": "abc"]) {
let flattened = context.flatten()
$0.it("allows you to flatten the context contents") {
try context.push(dictionary: ["test": "abc"]) {
let flattened = context.flatten()

try expect(flattened.count) == 2
try expect(flattened["name"] as? String) == "Kyle"
try expect(flattened["test"] as? String) == "abc"
try expect(flattened.count) == 2
try expect(flattened["name"] as? String) == "Kyle"
try expect(flattened["test"] as? String) == "abc"
}
}
}
}
Expand Down
Loading

0 comments on commit f7bda22

Please sign in to comment.