Update to Spectre 0.9.0 (#247)

* update to Spectre 0.9.0

* fix variable spec tests

* fix flatMap warning

* updated CHANGELOG
This commit is contained in:
Ilya Puchka
2018-09-23 03:46:27 +03:00
committed by GitHub
parent d238c25eef
commit f7bda226e8
26 changed files with 2386 additions and 2214 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,5 @@
.conche/ .conche/
.build/ .build/
Packages/ Packages/
Package.resolved
Package.pins Package.pins
*.xcodeproj *.xcodeproj

View File

@@ -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 %}` - 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) [Ilya Puchka](https://github.com/ilyapuchka)
[#243](https://github.com/stencilproject/Stencil/pull/243) [#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 }}`. - 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) [Ilya Puchka](https://github.com/ilyapuchka)
[#245](https://github.com/stencilproject/Stencil/pull/245) [#245](https://github.com/stencilproject/Stencil/pull/245)
@@ -35,6 +34,9 @@
- Updated the codebase to use Swift 4 features. - Updated the codebase to use Swift 4 features.
[David Jennes](https://github.com/djbe) [David Jennes](https://github.com/djbe)
[#239](https://github.com/stencilproject/Stencil/pull/239) [#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 ## 0.12.1

25
Package.resolved Normal file
View File

@@ -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
}

View File

@@ -8,7 +8,7 @@ let package = Package(
], ],
dependencies: [ dependencies: [
.package(url: "https://github.com/kylef/PathKit.git", from: "0.9.0"), .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: [ targets: [
.target(name: "Stencil", dependencies: [ .target(name: "Stencil", dependencies: [

View File

@@ -118,7 +118,7 @@ final class IfExpressionParser {
private init(components: ArraySlice<String>, tokenParser: TokenParser, token: Token) throws { private init(components: ArraySlice<String>, tokenParser: TokenParser, token: Token) throws {
var parsedComponents = Set<Int>() var parsedComponents = Set<Int>()
var bracketsBalance = 0 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 } guard !parsedComponents.contains(index) else { return nil }
if component == "(" { if component == "(" {

View File

@@ -1,3 +1,8 @@
import XCTest
import StencilTests import StencilTests
stencilTests() var tests = [XCTestCaseEntry]()
tests += StencilTests.__allTests()
XCTMain(tests)

View File

@@ -1,7 +1,10 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class ContextTests: XCTestCase {
func testContext() { func testContext() {
describe("Context") { describe("Context") {
var context: Context! var context: Context!
@@ -79,3 +82,4 @@ func testContext() {
} }
} }
} }
}

View File

@@ -1,8 +1,9 @@
import XCTest
import Spectre import Spectre
import PathKit import PathKit
@testable import Stencil @testable import Stencil
class EnvironmentTests: XCTestCase {
func testEnvironment() { func testEnvironment() {
describe("Environment") { describe("Environment") {
var environment: Environment! var environment: Environment!
@@ -330,6 +331,7 @@ func testEnvironment() {
} }
} }
}
extension Expectation { extension Expectation {
@discardableResult @discardableResult

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class ExpressionsTests: XCTestCase {
func testExpressions() { func testExpressions() {
describe("Expression") { describe("Expression") {
let parser = TokenParser(tokens: [], environment: Environment()) let parser = TokenParser(tokens: [], environment: Environment())
@@ -342,3 +343,4 @@ func testExpressions() {
} }
} }
} }
}

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class FilterTests: XCTestCase {
func testFilter() { func testFilter() {
describe("template filters") { describe("template filters") {
let context: [String: Any] = ["name": "Kyle"] let context: [String: Any] = ["name": "Kyle"]
@@ -368,3 +369,4 @@ func testFilter() {
} }
} }
} }
}

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
import Stencil import Stencil
class FilterTagTests: XCTestCase {
func testFilterTag() { func testFilterTag() {
describe("Filter Tag") { describe("Filter Tag") {
$0.it("allows you to use a filter") { $0.it("allows you to use a filter") {
@@ -47,3 +48,4 @@ func testFilterTag() {
} }
} }
} }
}

View File

@@ -1,8 +1,9 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
import Foundation import Foundation
class ForNodeTests: XCTestCase {
func testForNode() { func testForNode() {
describe("ForNode") { describe("ForNode") {
let context = Context(dictionary: [ let context = Context(dictionary: [
@@ -347,6 +348,7 @@ func testForNode() {
} }
} }
}
fileprivate struct Article { fileprivate struct Article {
let title: String let title: String

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class IfNodeTests: XCTestCase {
func testIfNode() { func testIfNode() {
describe("IfNode") { describe("IfNode") {
$0.describe("parsing") { $0.describe("parsing") {
@@ -285,3 +286,4 @@ func testIfNode() {
} }
} }
}

View File

@@ -1,8 +1,9 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
import PathKit import PathKit
class IncludeTests: XCTestCase {
func testInclude() { func testInclude() {
describe("Include") { describe("Include") {
let path = Path(#file) + ".." + "fixtures" let path = Path(#file) + ".." + "fixtures"
@@ -68,3 +69,4 @@ func testInclude() {
} }
} }
} }
}

View File

@@ -1,8 +1,9 @@
import XCTest
import Spectre import Spectre
import Stencil import Stencil
import PathKit import PathKit
class InheritenceTests: XCTestCase {
func testInheritence() { func testInheritence() {
describe("Inheritence") { describe("Inheritence") {
let path = Path(#file) + ".." + "fixtures" let path = Path(#file) + ".." + "fixtures"
@@ -34,3 +35,4 @@ func testInheritence() {
} }
} }
} }
}

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class LexerTests: XCTestCase {
func testLexer() { func testLexer() {
describe("Lexer") { describe("Lexer") {
$0.it("can tokenize text") { $0.it("can tokenize text") {
@@ -93,3 +94,4 @@ func testLexer() {
} }
} }
} }
}

View File

@@ -1,8 +1,9 @@
import XCTest
import Spectre import Spectre
import Stencil import Stencil
import PathKit import PathKit
class TemplateLoaderTests: XCTestCase {
func testTemplateLoader() { func testTemplateLoader() {
describe("FileSystemLoader") { describe("FileSystemLoader") {
let path = Path(#file) + ".." + "fixtures" let path = Path(#file) + ".." + "fixtures"
@@ -53,3 +54,4 @@ func testTemplateLoader() {
} }
} }
} }
}

View File

@@ -1,7 +1,7 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class ErrorNode : NodeType { class ErrorNode : NodeType {
let token: Token? let token: Token?
init(token: Token? = nil) { init(token: Token? = nil) {
@@ -13,7 +13,7 @@ class ErrorNode : NodeType {
} }
} }
class NodeTests: XCTestCase {
func testNode() { func testNode() {
describe("Node") { describe("Node") {
let context = Context(dictionary: [ let context = Context(dictionary: [
@@ -63,3 +63,4 @@ func testNode() {
} }
} }
} }
}

View File

@@ -1,8 +1,10 @@
import XCTest
import Foundation import Foundation
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class NowNodeTests: XCTestCase {
func testNowNode() { func testNowNode() {
#if !os(Linux) #if !os(Linux)
describe("NowNode") { describe("NowNode") {
@@ -41,3 +43,4 @@ func testNowNode() {
} }
#endif #endif
} }
}

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class TokenParserTests: XCTestCase {
func testTokenParser() { func testTokenParser() {
describe("TokenParser") { describe("TokenParser") {
$0.it("can parse a text token") { $0.it("can parse a text token") {
@@ -59,3 +60,4 @@ func testTokenParser() {
} }
} }
} }
}

View File

@@ -1,7 +1,7 @@
import XCTest
import Spectre import Spectre
import Stencil import Stencil
fileprivate struct CustomNode : NodeType { fileprivate struct CustomNode : NodeType {
let token: Token? let token: Token?
func render(_ context:Context) throws -> String { func render(_ context:Context) throws -> String {
@@ -9,13 +9,12 @@ fileprivate struct CustomNode : NodeType {
} }
} }
fileprivate struct Article { fileprivate struct Article {
let title: String let title: String
let author: String let author: String
} }
class StencilTests: XCTestCase {
func testStencil() { func testStencil() {
describe("Stencil") { describe("Stencil") {
let exampleExtension = Extension() let exampleExtension = Extension()
@@ -70,3 +69,4 @@ func testStencil() {
} }
} }
} }
}

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class TemplateTests: XCTestCase {
func testTemplate() { func testTemplate() {
describe("Template") { describe("Template") {
$0.it("can render a template from a string") { $0.it("can render a template from a string") {
@@ -18,3 +19,4 @@ func testTemplate() {
} }
} }
}

View File

@@ -1,7 +1,8 @@
import XCTest
import Spectre import Spectre
@testable import Stencil @testable import Stencil
class TokenTests: XCTestCase {
func testToken() { func testToken() {
describe("Token") { describe("Token") {
$0.it("can split the contents into components") { $0.it("can split the contents into components") {
@@ -32,3 +33,4 @@ func testToken() {
} }
} }
} }
}

View File

@@ -1,3 +1,4 @@
import XCTest
import Foundation import Foundation
import Spectre import Spectre
@testable import Stencil @testable import Stencil
@@ -29,6 +30,7 @@ fileprivate class Blog: WebSite {
let featuring: Article? = Article(author: Person(name: "Jhon")) let featuring: Article? = Article(author: Person(name: "Jhon"))
} }
class VariableTests: XCTestCase {
func testVariable() { func testVariable() {
describe("Variable") { describe("Variable") {
let context = Context(dictionary: [ let context = Context(dictionary: [
@@ -407,3 +409,4 @@ func testVariable() {
} }
} }
} }
}

View File

@@ -1,30 +0,0 @@
import XCTest
public func stencilTests() {
testContext()
testFilter()
testLexer()
testToken()
testTokenParser()
testTemplateLoader()
testTemplate()
testVariable()
testNode()
testForNode()
testExpressions()
testIfNode()
testNowNode()
testInclude()
testInheritence()
testFilterTag()
testEnvironment()
testStencil()
}
class StencilTests: XCTestCase {
func testRunStencilTests() {
stencilTests()
}
}

View File

@@ -0,0 +1,134 @@
import XCTest
extension ContextTests {
static let __allTests = [
("testContext", testContext),
]
}
extension EnvironmentTests {
static let __allTests = [
("testEnvironment", testEnvironment),
]
}
extension ExpressionsTests {
static let __allTests = [
("testExpressions", testExpressions),
]
}
extension FilterTagTests {
static let __allTests = [
("testFilterTag", testFilterTag),
]
}
extension FilterTests {
static let __allTests = [
("testFilter", testFilter),
]
}
extension ForNodeTests {
static let __allTests = [
("testForNode", testForNode),
]
}
extension IfNodeTests {
static let __allTests = [
("testIfNode", testIfNode),
]
}
extension IncludeTests {
static let __allTests = [
("testInclude", testInclude),
]
}
extension InheritenceTests {
static let __allTests = [
("testInheritence", testInheritence),
]
}
extension LexerTests {
static let __allTests = [
("testLexer", testLexer),
]
}
extension NodeTests {
static let __allTests = [
("testNode", testNode),
]
}
extension NowNodeTests {
static let __allTests = [
("testNowNode", testNowNode),
]
}
extension StencilTests {
static let __allTests = [
("testStencil", testStencil),
]
}
extension TemplateLoaderTests {
static let __allTests = [
("testTemplateLoader", testTemplateLoader),
]
}
extension TemplateTests {
static let __allTests = [
("testTemplate", testTemplate),
]
}
extension TokenParserTests {
static let __allTests = [
("testTokenParser", testTokenParser),
]
}
extension TokenTests {
static let __allTests = [
("testToken", testToken),
]
}
extension VariableTests {
static let __allTests = [
("testVariable", testVariable),
]
}
#if !os(macOS)
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(ContextTests.__allTests),
testCase(EnvironmentTests.__allTests),
testCase(ExpressionsTests.__allTests),
testCase(FilterTagTests.__allTests),
testCase(FilterTests.__allTests),
testCase(ForNodeTests.__allTests),
testCase(IfNodeTests.__allTests),
testCase(IncludeTests.__allTests),
testCase(InheritenceTests.__allTests),
testCase(LexerTests.__allTests),
testCase(NodeTests.__allTests),
testCase(NowNodeTests.__allTests),
testCase(StencilTests.__allTests),
testCase(TemplateLoaderTests.__allTests),
testCase(TemplateTests.__allTests),
testCase(TokenParserTests.__allTests),
testCase(TokenTests.__allTests),
testCase(VariableTests.__allTests),
]
}
#endif