-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d30237
commit c1fc750
Showing
9 changed files
with
511 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,78 @@ | ||
// import { arbitraryQuery } from "../output/output"; | ||
import * as Codegen from "./convert"; | ||
import * as Types from "./types"; | ||
|
||
describe("includesOneOf", () => { | ||
it("Makes any sense whatsoever", () => { | ||
expect(Codegen.includesOneOf("dog", ["dog"])).toBeTruthy(); | ||
}); | ||
it("Works with multiple", () => { | ||
expect(Codegen.includesOneOf("dog", ["log", "dog"])).toBeTruthy(); | ||
}); | ||
it("Works with multiple even with nonsense everywhere", () => { | ||
expect(Codegen.includesOneOf("_____dog___", ["log", "dog"])).toBeTruthy(); | ||
}); | ||
it("Doesn't find something that's not there", () => { | ||
expect(Codegen.includesOneOf("dog", ["log"])).toBeFalsy(); | ||
}); | ||
}); | ||
const stable: Types.Output = { | ||
kind: "Object", | ||
name: "Stable" as Types.TypeName, | ||
output: "fc.record({horse: arbitraryHorse })" as Types.Generated, | ||
deps: ["Horse" as Types.TypeName] | ||
}; | ||
const horse: Types.Output = { | ||
kind: "Object", | ||
name: "Horse" as Types.TypeName, | ||
output: "fc.record({saddle: arbitrarySaddle})" as Types.Generated, | ||
deps: ["Saddle" as Types.TypeName] | ||
}; | ||
const saddle: Types.Output = { | ||
kind: "Object", | ||
name: "Saddle" as Types.TypeName, | ||
output: "fc.record({chair: arbitraryChair})" as Types.Generated, | ||
deps: [] | ||
}; | ||
const things: Types.Output = { | ||
kind: "Union", | ||
name: "Things" as Types.TypeName, | ||
output: "fc.oneof(arbitraryStable, arbitrarySaddle)" as Types.Generated, | ||
deps: ["Stable" as Types.TypeName, "Saddle" as Types.TypeName] | ||
}; | ||
|
||
describe("sortASTs", () => { | ||
it("Puts mentions later", () => { | ||
const stable: Types.Output = { | ||
kind: "Object", | ||
name: "Stable" as Types.TypeName, | ||
output: "fc.record({horse: arbitraryHorse })" as Types.Generated, | ||
deps: [], | ||
}; | ||
const horse: Types.Output = { | ||
kind: "Object", | ||
name: "Horse" as Types.TypeName, | ||
output: "fc.record({saddle: arbitrarySaddle})" as Types.Generated, | ||
deps: [], | ||
}; | ||
const saddle: Types.Output = { | ||
kind: "Object", | ||
name: "Saddle" as Types.TypeName, | ||
output: "fc.record({chair: arbitraryChair})" as Types.Generated, | ||
deps: [], | ||
}; | ||
const things: Types.Output = { | ||
kind: "Union", | ||
name: "Things" as Types.TypeName, | ||
output: "fc.oneof(arbitraryStable, arbitrarySaddle)" as Types.Generated, | ||
deps: [], | ||
}; | ||
const expectedOrder = [saddle, horse, stable, things]; | ||
expect(Codegen.sortASTs([things, stable, horse, saddle])).toStrictEqual( | ||
expectedOrder | ||
); | ||
expect(Codegen.sortASTs([stable, horse, saddle, things])).toStrictEqual( | ||
expectedOrder | ||
); | ||
}); | ||
|
||
it("Does the twitter ones", () => { | ||
const Query: Types.Output = { | ||
kind: "Object", | ||
name: "Query" as Types.TypeName, | ||
output: `fc.record({Tweet: arbitraryTweet,Tweets: fc.array(arbitraryTweet),TweetsMeta: arbitraryMeta,User: arbitraryUser,Notifications: fc.array(arbitraryNotification),NotificationsMeta: arbitraryMeta})` as Types.Generated, | ||
deps: [], | ||
}; | ||
const Tweet: Types.Output = { | ||
kind: "Object", | ||
name: "Tweet" as Types.TypeName, | ||
output: `fc.record({id: arbitraryID,body: arbitraryString,date: arbitraryDate,Author: arbitraryUser,Stats: arbitraryStat})` as Types.Generated, | ||
deps: [], | ||
}; | ||
const User: Types.Output = { | ||
kind: "Object", | ||
name: "User" as Types.TypeName, | ||
output: `fc.record({id: arbitraryID,username: arbitraryString,first_name: arbitraryString,last_name: arbitraryString,full_name: arbitraryString,name: arbitraryString,avatar_url: arbitraryUrl})` as Types.Generated, | ||
deps: [], | ||
}; | ||
const Stat: Types.Output = { | ||
kind: "Object", | ||
name: "Stat" as Types.TypeName, | ||
output: `fc.record({views: arbitraryInt,likes: arbitraryInt,retweets: arbitraryInt,responses: arbitraryInt})` as Types.Generated, | ||
deps: [], | ||
}; | ||
const Meta: Types.Output = { | ||
kind: "Object", | ||
name: "Meta" as Types.TypeName, | ||
output: `fc.record({count: arbitraryInt})` as Types.Generated, | ||
deps: [], | ||
}; | ||
|
||
const Notification: Types.Output = { | ||
kind: "Object", | ||
name: "Notification" as Types.TypeName, | ||
output: `fc.record({id: arbitraryID,date: arbitraryDate,type: arbitraryString})` as Types.Generated, | ||
deps: [], | ||
}; | ||
|
||
const Mutation: Types.Output = { | ||
kind: "Object", | ||
name: "Mutation" as Types.TypeName, | ||
output: `fc.record({createTweet: arbitraryTweet,deleteTweet: arbitraryTweet,markTweetRead: arbitraryBoolean})` as Types.Generated, | ||
deps: [], | ||
}; | ||
|
||
const StatOrNotification: Types.Output = { | ||
kind: "Union", | ||
name: "StatOrNotification" as Types.TypeName, | ||
output: `fc.oneof(arbitraryStat, arbitraryNotification)` as Types.Generated, | ||
deps: [], | ||
}; | ||
|
||
const expectedTweetOrder = [ | ||
User, | ||
Stat, | ||
Tweet, | ||
Meta, | ||
Notification, | ||
Query, | ||
Mutation, | ||
StatOrNotification, | ||
const expectedOrder = [ | ||
"Saddle" as Types.TypeName, | ||
"Horse" as Types.TypeName, | ||
"Stable" as Types.TypeName, | ||
"Things" as Types.TypeName | ||
]; | ||
expect( | ||
Codegen.sortASTs([ | ||
Query, | ||
Tweet, | ||
User, | ||
Stat, | ||
Meta, | ||
Notification, | ||
Mutation, | ||
StatOrNotification, | ||
]) | ||
).toStrictEqual(expectedTweetOrder); | ||
Codegen.sortASTs([things, stable, horse, saddle]).map(a => a.name) | ||
).toStrictEqual(expectedOrder); | ||
expect( | ||
Codegen.sortASTs([stable, horse, saddle, things]).map(a => a.name) | ||
).toStrictEqual(expectedOrder); | ||
}); | ||
}); | ||
|
||
describe("moveASTs", () => { | ||
it("Moves everything with zero deps", () => { | ||
const used: Types.Output[] = []; | ||
const remaining = [stable, horse, saddle, things]; | ||
const result = Codegen.moveASTs(used, remaining); | ||
if (result._tag === "Right") { | ||
expect(result.payload.used.length).toEqual(1); | ||
expect(result.payload.remaining.length).toEqual(3); | ||
} else { | ||
throw "moveASTs failed"; | ||
} | ||
}); | ||
it("Moves everything with deps that have already been moved across", () => { | ||
const used = [saddle]; | ||
const remaining = [horse, stable, things]; | ||
const result = Codegen.moveASTs(used, remaining); | ||
if (result._tag === "Right") { | ||
expect(result.payload.used.length).toEqual(2); | ||
expect(result.payload.remaining.length).toEqual(2); | ||
} else { | ||
throw "moveASTs failed"; | ||
} | ||
}); | ||
it("Bruce forces it to a satifying conclusion", () => { | ||
const remaining = [stable, horse, saddle, things]; | ||
const result = Codegen.magicSort(remaining, 100); | ||
if (result._tag === "Right") { | ||
expect(result && result.payload.length).toEqual(4); | ||
} else { | ||
throw "fail!"; | ||
} | ||
}); | ||
}); |
Oops, something went wrong.