Skip to content

Commit

Permalink
Add lexing of commas and fix SwiftLint warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
slashmo committed Dec 9, 2018
1 parent 71e2b73 commit 5f16dc4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions Sources/GraphQL/Language/Lexer/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ private let punctuationTokens: [UInt32: Lexer.Token.Kind] = [
38: .ampersand,
40: .openingParenthesis,
41: .closingParenthesis,
44: .comma,
46: .spread,
58: .colon,
61: .equals,
Expand Down
1 change: 1 addition & 0 deletions Sources/GraphQL/Language/Lexer/Token.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extension Lexer.Token {
case ampersand
case openingParenthesis
case closingParenthesis
case comma
case int
case float
case spread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ final class LexerPunctuationTokenTestCase: XCTestCase {
XCTAssertLexing("!", spitsOutPunctuationTokenOfKind: .bang)
}

func testItLexesCommas() {
XCTAssertLexing(",", spitsOutPunctuationTokenOfKind: .comma)
}

func testItLexesDollars() {
XCTAssertLexing("$", spitsOutPunctuationTokenOfKind: .dollar)
}
Expand Down
32 changes: 16 additions & 16 deletions Tests/GraphQLTests/Language/Lexer/LexerTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ import XCTest
@testable import GraphQL

final class LexerTestCase: XCTestCase {
func testItLexesAComplexQuery() {
let query = """
{
viewer {
...SmallUser
followers(first: 100) {
edges {
node {
...SmallUser
}
private let validGraphQLQuery = """
{
viewer {
...SmallUser
followers(first: 100) {
edges {
node {
...SmallUser
}
}
}
}
}
fragment SmallUser on User {
id
name
}
"""
fragment SmallUser on User {
id
name
}
"""

XCTAssertLexing(query, spitsOut: [
func testItLexesAComplexQuery() {
XCTAssertLexing(validGraphQLQuery, spitsOut: [
Lexer.Token(ofKind: GraphQL.Lexer.Token.Kind.openingBrace, startingAt: 0, endingAt: 1),
Lexer.Token(ofKind: GraphQL.Lexer.Token.Kind.name, startingAt: 3, endingAt: 9, holding: "viewer"),
Lexer.Token(ofKind: GraphQL.Lexer.Token.Kind.openingBrace, startingAt: 10, endingAt: 11),
Expand Down

0 comments on commit 5f16dc4

Please sign in to comment.