Skip to content

Commit

Permalink
Merge pull request #6 from thousandyears/oliver/nested-own-type
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieatkinson authored Aug 7, 2022
2 parents 7b264c1 + 0be23d5 commit a939924
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Sources/Lexicon/Lemma.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@ extension Lemma {
for id in node.type {
o[id] = lexicon.dictionary[id].map(Unowned.init)
}
} else {
for id in (parent?.node.type).or([]) {
guard let node = lexicon.dictionary[id]?.children[name] else { continue }
} else if let parent = lineage.first(where: \.isGraphNode) {
let descendant = id.dotPath(after: parent.id).split(separator: ".").map(Name.init)
for id in parent.node.type {
guard let node = lexicon.dictionary[id]?[descendant] else { continue }
o[node.id] = Unowned(node)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/lexicon-generate/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct CodeGeneratorCommand: AsyncParsableCommand {
TaskPaper(Data(contentsOf: input)).decode()
)
let json = await lexicon.json()
let code = try type.map { command in
let code = try type.map { command -> (URL, Data) in
guard let generator = Lexicon.Graph.JSON.generators.find(command) else {
fatalError("Unable to find a generator for \(command)")
}
Expand Down
57 changes: 57 additions & 0 deletions Tests/LexiconTests/Lemma™.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,61 @@ final class Lemma™: Hopes {
hope.false(Lemma.isValid(character: "_", appendingTo: "not_another_"))
hope.false(Lemma.isValid(character: "_", appendingTo: "")) // TODO: consider allowing this!
}

func test_inherited_node_own_type() async throws {

let root = try await Lexicon.from(
TaskPaper(inherited_node_own_type).decode()
).root

let userId = try await root["user", "id"].hopefully()
let collectionId = try await root["db", "collection", "id"].hopefully()

let isCollectionId = await userId.is(collectionId)

hope(isCollectionId) == true
}

func test_inherited_node_own_type_nested() async throws {

let root = try await Lexicon.from(
TaskPaper(inherited_node_own_type).decode()
).root

do {
let a = try await root["user", "b", "c"].hopefully()
let b = try await root["a", "b", "c"].hopefully()
let matches = await a.is(b)
hope(matches) == true
}

do {
let a = try await root["a", "two", "two", "two", "three"].hopefully()
let b = try await root["one", "two", "three"].hopefully()
let matches = await a.is(b)
hope(matches) == true
}
}
}

private let inherited_node_own_type = """
root:
a:
+ root.one
b:
+ root.two
c:
+ root.three
one:
two:
+ root.a
three:
+ root.b
db:
collection:
id:
user:
+ root.db.collection
+ root.a
"""

23 changes: 0 additions & 23 deletions Tests/LexiconTests/Lexicon™.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ final class Lexicon™: Hopes {

// TODO: ...
}

func test_inherited_node_own_type() async throws {

let root = try await Lexicon.from(
TaskPaper(inherited_node_own_type).decode()
).root

let userId = try await root["user", "id"].hopefully()
let collectionId = try await root["db", "collection", "id"].hopefully()

let isCollectionId = await userId.is(collectionId)

hope(isCollectionId) == true
}
}

private let taskpaper = """
Expand Down Expand Up @@ -91,12 +77,3 @@ root:
json:
taskpaper:
"""

private let inherited_node_own_type = """
root:
db:
collection:
id:
user:
+ root.db.collection
"""

0 comments on commit a939924

Please sign in to comment.