Skip to content

Commit

Permalink
Clarfy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pietbrauer committed Oct 20, 2015
1 parent 632cb38 commit 62a043c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
3 changes: 0 additions & 3 deletions Common/Framework/States/Named.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public class Named : TokenizationState {
//Create a "new" named state with the root set as a clone of our root
let newState = Named(name:name,root: rootState.clone())

// println(self.rootState.description)
// println(newState.rootState.description)

newState.endState = newState.rootState.lowLeaf()
newState.cloneTimeEnd = endState

Expand Down
7 changes: 1 addition & 6 deletions OysterKit/OysterKitTests/parserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ class parserTests: XCTestCase {

//Create a tokenizer from the generated description
let generatedTokenizer = parser.parse(tokFileTokDef)
var parserErrors = ""
for error in parser.errors {
parserErrors += "\t\(error)\n"
}

XCTAssert(parserErrors.characters.count == 0, "Self parsing generated an error: \(parserErrors) with \(tokFileTokDef)")
XCTAssert(parser.errors.count == 0)

//Tokenize original serialized description with the parsed tokenizer built from my own serialized description
let parserGeneratedTokens = generatedTokenizer.tokenize(tokFileTokDef)
Expand Down
62 changes: 54 additions & 8 deletions OysterKit/OysterKitTests/standardTokensTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ class standardTokensTest: XCTestCase {
)

let parsingTest = "Short 10 string"


XCTAssert(tokenizer.tokenize(parsingTest) == [token("word",chars:"Short"), token("blank",chars:" "), token("integer",chars:"10"), token("blank",chars:" "), token("word",chars:"string"), ])
let reference = [
token("word", chars: "Short"),
token("blank", chars: " "),
token("integer", chars: "10"),
token("blank", chars: " "),
token("word", chars: "string")
]
XCTAssertEqual(tokenizer.tokenize(parsingTest), reference)
}

func testWhiteSpaces(){
Expand All @@ -87,11 +92,28 @@ class standardTokensTest: XCTestCase {
)

let parsingTest = "Short\tlittle\nstring that\n tries \tto break \n\tthings up"

__debugScanning = true

let tokens = tokenizer.tokenize(parsingTest)
assertTokenListsEqual(tokens, reference: [token("word",chars:"Short"), token("whitespace",chars:"\t"), token("word",chars:"little"), token("whitespace",chars:"\n"), token("word",chars:"string"), token("whitespace",chars:" "), token("word",chars:"that"), token("whitespace",chars:"\n "), token("word",chars:"tries"), token("whitespace",chars:" \t"), token("word",chars:"to"), token("whitespace",chars:" "), token("word",chars:"break"), token("whitespace",chars:" \n\t"), token("word",chars:"things"), token("whitespace",chars:" "), token("word",chars:"up"), ])
__debugScanning = false
let reference = [
token("word", chars: "Short"),
token("whitespace", chars: "\t"),
token("word", chars: "little"),
token("whitespace", chars: "\n"),
token("word", chars: "string"),
token("whitespace", chars: " "),
token("word", chars: "that"),
token("whitespace", chars: "\n "),
token("word", chars: "tries"),
token("whitespace", chars: " \t"),
token("word", chars: "to"),
token("whitespace", chars: " "),
token("word", chars: "break"),
token("whitespace", chars: " \n\t"),
token("word", chars: "things"),
token("whitespace", chars: " "),
token("word", chars: "up")
]
XCTAssertEqual(tokens, reference)
}

func testQuotedString(){
Expand All @@ -105,7 +127,31 @@ class standardTokensTest: XCTestCase {
)

let parsingTest = "A great man once said \"It is a far better thing that I do now than I have ever done\". "
let reference = [
token("word", chars:"A"),
token("blank", chars:" "),
token("word", chars:"great"),
token("blank", chars:" "),
token("word", chars:"man"),
token("blank", chars:" "),
token("word", chars:"once"),
token("blank", chars:" "),
token("word", chars:"said"),
token("blank", chars:" "),
token("double-quote", chars:"\""),
token("quoted-string", chars:"It is a far better thing that I do now than I have ever done"),
token("double-quote", chars:"\""),
token("punct", chars:"."),
token("blank", chars:" ")
]

assertTokenListsEqual(tokenizer.tokenize(parsingTest), reference: [token("word",chars:"A"), token("blank",chars:" "), token("word",chars:"great"), token("blank",chars:" "), token("word",chars:"man"), token("blank",chars:" "), token("word",chars:"once"), token("blank",chars:" "), token("word",chars:"said"), token("blank",chars:" "), token("double-quote",chars:"\""), token("quoted-string",chars:"It is a far better thing that I do now than I have ever done"), token("double-quote",chars:"\""), token("punct",chars:"."), token("blank",chars:" "), ])
XCTAssertEqual(tokenizer.tokenize(parsingTest), reference)
}
}

extension Token: Equatable {}

public func ==(lhs: Token, rhs: Token) -> Bool {
return lhs.name == rhs.name &&
lhs.characters == rhs.characters
}

0 comments on commit 62a043c

Please sign in to comment.