Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/app-framework/__tests__/getIn.test.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/**6* Need to test permutations of (at all depths):7* TypedMap -> immutable.List -> immutable.Map8*9*/101112import * as Immutable from "immutable";13import { expectType } from "tsd";1415import { TypedCollectionMethods } from "@cocalc/util/types/immutable-types";16import { TypedMap } from "@cocalc/util/types/typed-map";1718// TODO: Iterate through appropriate base types19type BASE = string;20const assign: BASE = "0";2122type GetIn<T> = TypedCollectionMethods<T>["getIn"];23const STUB = (() => null) as any; // No implementation2425// Seems trivial an unecessary but imagine a variable array that may turn26// out to have only one arg. We still want to type that correctly.27describe("length 1", () => {28test("[obj]", () => {29type T = { str: BASE };30const getIn: GetIn<T> = STUB;31let test = getIn(["str"]);32test = assign; // Checks against never33expectType<BASE>(test); // Finally check against the BASE type again34});35test("[Array]", () => {36type T = BASE[];37const getIn: GetIn<T> = STUB;38let test = getIn([0]);39test = assign;40expectType<BASE>(test);41});42test("[TypedMap]", () => {43type T = TypedMap<{ str: BASE }>;44const getIn: GetIn<T> = STUB;45let test = getIn(["str"]);46test = assign; // Checks against never47expectType<BASE>(test); // Finally check against the BASE type again48});49test("[List]", () => {50type T = Immutable.List<BASE>;51const getIn: GetIn<T> = STUB;52let test = getIn([0]);53test = assign;54expectType<BASE>(test);55});56test("[Map]", () => {57type T = Immutable.Map<string, BASE>;58const getIn: GetIn<T> = STUB;59let test = getIn(["anystr"]);60test = assign; // Checks against never61expectType<BASE>(test); // Finally check against the BASE type again62});63});6465describe("length 2", () => {66test("[obj, obj]", () => {67type T = { foo: { str: BASE } };68const getIn: GetIn<T> = STUB;69let test = getIn(["foo", "str"]);70test = assign; // Checks against never71expectType<BASE>(test); // Finally check against the BASE type again72});73test("[obj, Array]", () => {74type T = { foo: BASE[] };75const getIn: GetIn<T> = STUB;76let test = getIn(["foo", 0]);77test = assign;78expectType<BASE>(test);79});80test("[obj, TypedMap]", () => {81type T = { foo: TypedMap<{ str: BASE }> };82const getIn: GetIn<T> = STUB;83let test = getIn(["foo", "str"]);84test = assign; // Checks against never85expectType<BASE>(test); // Finally check against the BASE type again86});87test("[obj, List]", () => {88type T = { foo: Immutable.List<BASE> };89const getIn: GetIn<T> = STUB;90let test = getIn(["foo", 0]);91test = assign;92expectType<BASE>(test);93});94test("[obj, Map]", () => {95type T = { foo: Immutable.Map<string, BASE> };96const getIn: GetIn<T> = STUB;97let test = getIn(["foo", "anystr"]);98test = assign; // Checks against never99expectType<BASE>(test); // Finally check against the BASE type again100});101102test("[Array, obj]", () => {103type T = { str: BASE }[];104const getIn: GetIn<T> = STUB;105let test = getIn([0, "str"]);106107test = assign; // Checks against never108expectType<BASE>(test); // Finally check against the BASE type again109});110test("[Array, Array]", () => {111type T = BASE[][];112const getIn: GetIn<T> = STUB;113let test = getIn([0, 0]);114test = assign;115expectType<BASE>(test);116});117test("[Array, TypedMap]", () => {118type T = TypedMap<{ str: BASE }>[];119const getIn: GetIn<T> = STUB;120let test = getIn([0, "str"]);121test = assign; // Checks against never122expectType<BASE>(test); // Finally check against the BASE type again123});124test("[Array, List]", () => {125type T = Immutable.List<BASE>[];126const getIn: GetIn<T> = STUB;127let test = getIn([0, 0]);128test = assign;129expectType<BASE>(test);130});131test("[Array, Map]", () => {132type T = Immutable.Map<string, BASE>[];133const getIn: GetIn<T> = STUB;134let test = getIn([0, "anystr"]);135test = assign; // Checks against never136expectType<BASE>(test); // Finally check against the BASE type again137});138});139140describe("length 3", () => {141describe("object -> L3", () => {142test("[obj, obj, obj]", () => {143type T = { foo: { bar: { str: BASE } } };144const getIn: GetIn<T> = STUB;145let test = getIn(["foo", "bar", "str"]);146test = assign; // Checks against never147expectType<BASE>(test); // Finally check against the BASE type again148});149test("[obj, obj, Array]", () => {150type T = { foo: { bar: BASE[] } };151const getIn: GetIn<T> = STUB;152let test = getIn(["foo", "bar", 0]);153test = assign;154expectType<BASE>(test);155});156test("[obj, obj, TypedMap]", () => {157type T = { foo: { bar: TypedMap<{ str: BASE }> } };158const getIn: GetIn<T> = STUB;159let test = getIn(["foo", "bar", "str"]);160test = assign; // Checks against never161expectType<BASE>(test); // Finally check against the BASE type again162});163test("[obj, obj, List]", () => {164type T = { foo: { bar: Immutable.List<BASE> } };165const getIn: GetIn<T> = STUB;166let test = getIn(["foo", "bar", 0]);167test = assign;168expectType<BASE>(test);169});170test("[obj, obj, Map]", () => {171type T = { foo: { bar: Immutable.Map<string, BASE> } };172const getIn: GetIn<T> = STUB;173let test = getIn(["foo", "bar", "anystr"]);174test = assign; // Checks against never175expectType<BASE>(test); // Finally check against the BASE type again176});177});178179describe("Array -> L3", () => {180test("[obj, Array, obj]", () => {181type T = { foo: { str: BASE }[] };182const getIn: GetIn<T> = STUB;183let test = getIn(["foo", 0, "str"]);184test = assign; // Checks against never185expectType<BASE>(test); // Finally check against the BASE type again186});187test("[obj, Array, Array]", () => {188type T = { foo: BASE[][] };189const getIn: GetIn<T> = STUB;190let test = getIn(["foo", 2, 0]);191test = assign;192expectType<BASE>(test);193});194test("[obj, Array, TypedMap]", () => {195type T = { foo: TypedMap<{ str: BASE }>[] };196const getIn: GetIn<T> = STUB;197let test = getIn(["foo", 2, "str"]);198test = assign; // Checks against never199expectType<BASE>(test); // Finally check against the BASE type again200});201test("[obj, Array, List]", () => {202type T = { foo: Immutable.List<BASE>[] };203const getIn: GetIn<T> = STUB;204let test = getIn(["foo", 2, 0]);205test = assign;206expectType<BASE>(test);207});208test("[obj, Array, Map]", () => {209type T = { foo: Immutable.Map<string, BASE>[] };210const getIn: GetIn<T> = STUB;211let test = getIn(["foo", 2, "anystr"]);212test = assign; // Checks against never213expectType<BASE>(test); // Finally check against the BASE type again214});215});216217describe("TypedMap -> L3", () => {218test("[obj, TypedMap, obj]", () => {219type T = { foo: TypedMap<{ bar: { str: BASE } }> };220const getIn: GetIn<T> = STUB;221let test = getIn(["foo", "bar", "str"]);222test = assign; // Checks against never223expectType<BASE>(test); // Finally check against the BASE type again224});225test("[obj, TypedMap, Array]", () => {226type T = { foo: TypedMap<{ bar: BASE[] }> };227const getIn: GetIn<T> = STUB;228let test = getIn(["foo", "bar", 0]);229test = assign;230expectType<BASE>(test);231});232test("[obj, TypedMap, TypedMap]", () => {233type T = { foo: TypedMap<{ bar: TypedMap<{ str: BASE }> }> };234const getIn: GetIn<T> = STUB;235let test = getIn(["foo", "bar", "str"]);236test = assign; // Checks against never237expectType<BASE>(test); // Finally check against the BASE type again238});239test("[obj, TypedMap, List]", () => {240type T = { foo: TypedMap<{ bar: Immutable.List<BASE> }> };241const getIn: GetIn<T> = STUB;242let test = getIn(["foo", "bar", 0]);243test = assign;244expectType<BASE>(test);245});246test("[obj, TypedMap, Map]", () => {247type T = { foo: TypedMap<{ bar: Immutable.Map<string, BASE> }> };248const getIn: GetIn<T> = STUB;249let test = getIn(["foo", "bar", "anystr"]);250test = assign; // Checks against never251expectType<BASE>(test); // Finally check against the BASE type again252});253});254255describe("List -> L3", () => {256test("[obj, List, obj]", () => {257type T = { foo: Immutable.List<{ str: BASE }> };258const getIn: GetIn<T> = STUB;259let test = getIn(["foo", 0, "str"]);260test = assign; // Checks against never261expectType<BASE>(test); // Finally check against the BASE type again262});263test("[obj, List, TypedMap]", () => {264type T = { foo: Immutable.List<TypedMap<{ str: BASE }>> };265const getIn: GetIn<T> = STUB;266let test = getIn(["foo", 0, "str"]);267test = assign; // Checks against never268expectType<BASE>(test); // Finally check against the BASE type again269});270test("[obj, List, List]", () => {271type T = { foo: Immutable.List<Immutable.List<BASE>> };272const getIn: GetIn<T> = STUB;273let test = getIn(["foo", 0, 0]);274test = assign;275expectType<BASE>(test);276});277test("[obj, List, Array]", () => {278type T = { foo: Immutable.List<BASE[]> };279const getIn: GetIn<T> = STUB;280let test = getIn(["foo", 0, 0]);281test = assign;282expectType<BASE>(test);283});284test("[obj, List, Map]", () => {285type T = { foo: Immutable.List<Immutable.Map<string, BASE>> };286const getIn: GetIn<T> = STUB;287let test = getIn(["foo", 0, "anystr"]);288test = assign; // Checks against never289expectType<BASE>(test); // Finally check against the BASE type again290});291});292293describe("Map -> L3", () => {294test("[obj, Map, obj]", () => {295type T = { foo: Immutable.Map<string, { str: BASE }> };296const getIn: GetIn<T> = STUB;297let test = getIn(["foo", "anystr", "str"]);298test = assign; // Checks against never299expectType<BASE>(test); // Finally check against the BASE type again300});301test("[obj, Map, TypedMap]", () => {302type T = { foo: Immutable.Map<string, TypedMap<{ str: BASE }>> };303const getIn: GetIn<T> = STUB;304let test = getIn(["foo", "anystr", "str"]);305test = assign; // Checks against never306expectType<BASE>(test); // Finally check against the BASE type again307});308test("[obj, Map, List]", () => {309type T = { foo: Immutable.Map<string, Immutable.List<BASE>> };310const getIn: GetIn<T> = STUB;311let test = getIn(["foo", "anystr", 0]);312test = assign;313expectType<BASE>(test);314});315test("[obj, Map, Array]", () => {316type T = { foo: Immutable.Map<string, BASE[]> };317const getIn: GetIn<T> = STUB;318let test = getIn(["foo", "anystr", 0]);319test = assign;320expectType<BASE>(test);321});322test("[obj, Map, Map]", () => {323type T = { foo: Immutable.Map<string, Immutable.Map<string, BASE>> };324const getIn: GetIn<T> = STUB;325let test = getIn(["foo", "anystr", "anystr"]);326test = assign; // Checks against never327expectType<BASE>(test); // Finally check against the BASE type again328});329});330});331332describe("length 4", () => {333describe("object -> L4", () => {334test("[obj, obj, obj, obj]", () => {335type T = { foo: { foo: { bar: { str: BASE } } } };336const getIn: GetIn<T> = STUB;337let test = getIn(["foo", "foo", "bar", "str"]);338test = assign; // Checks against never339expectType<BASE>(test); // Finally check against the BASE type again340});341test("[obj, obj, obj, Array]", () => {342type T = { foo: { foo: { bar: BASE[] } } };343const getIn: GetIn<T> = STUB;344let test = getIn(["foo", "foo", "bar", 0]);345test = assign;346expectType<BASE>(test);347});348test("[obj, obj, obj, TypedMap]", () => {349type T = { foo: { foo: { bar: TypedMap<{ str: BASE }> } } };350const getIn: GetIn<T> = STUB;351let test = getIn(["foo", "foo", "bar", "str"]);352test = assign; // Checks against never353expectType<BASE>(test); // Finally check against the BASE type again354});355test("[obj, obj, obj, List]", () => {356type T = { foo: { foo: { bar: Immutable.List<BASE> } } };357const getIn: GetIn<T> = STUB;358let test = getIn(["foo", "foo", "bar", 0]);359test = assign;360expectType<BASE>(test);361});362test("[obj, obj, obj, Map]", () => {363type T = { foo: { foo: { bar: Immutable.Map<string, BASE> } } };364const getIn: GetIn<T> = STUB;365let test = getIn(["foo", "foo", "bar", "anystr"]);366test = assign; // Checks against never367expectType<BASE>(test); // Finally check against the BASE type again368});369});370371describe("Array -> L4", () => {372test("[obj, obj, Array, obj]", () => {373type T = { foo: { foo: { str: BASE }[] } };374const getIn: GetIn<T> = STUB;375let test = getIn(["foo", "foo", 0, "str"]);376test = assign; // Checks against never377expectType<BASE>(test); // Finally check against the BASE type again378});379test("[obj, obj, Array, Array]", () => {380type T = { foo: { foo: BASE[][] } };381const getIn: GetIn<T> = STUB;382let test = getIn(["foo", "foo", 2, 0]);383test = assign;384expectType<BASE>(test);385});386test("[obj, obj, Array, TypedMap]", () => {387type T = { foo: { foo: TypedMap<{ str: BASE }>[] } };388const getIn: GetIn<T> = STUB;389let test = getIn(["foo", "foo", 2, "str"]);390test = assign; // Checks against never391expectType<BASE>(test); // Finally check against the BASE type again392});393test("[obj, obj, Array, List]", () => {394type T = { foo: { foo: Immutable.List<BASE>[] } };395const getIn: GetIn<T> = STUB;396let test = getIn(["foo", "foo", 2, 0]);397test = assign;398expectType<BASE>(test);399});400test("[obj, obj, Array, Map]", () => {401type T = { foo: { foo: Immutable.Map<string, BASE>[] } };402const getIn: GetIn<T> = STUB;403let test = getIn(["foo", "foo", 2, "anystr"]);404test = assign; // Checks against never405expectType<BASE>(test); // Finally check against the BASE type again406});407});408409describe("TypedMap -> L4", () => {410test("[obj, obj, TypedMap, obj]", () => {411type T = { foo: { foo: TypedMap<{ bar: { str: BASE } }> } };412const getIn: GetIn<T> = STUB;413let test = getIn(["foo", "foo", "bar", "str"]);414415test = assign; // Checks against never416expectType<BASE>(test); // Finally check against the BASE type again417});418test("[obj, obj, TypedMap, Array]", () => {419type T = { foo: { foo: TypedMap<{ bar: BASE[] }> } };420const getIn: GetIn<T> = STUB;421let test = getIn(["foo", "foo", "bar", 0]);422test = assign;423expectType<BASE>(test);424});425test("[obj, obj, TypedMap, TypedMap]", () => {426type T = { foo: { foo: TypedMap<{ bar: TypedMap<{ str: BASE }> }> } };427const getIn: GetIn<T> = STUB;428let test = getIn(["foo", "foo", "bar", "str"]);429test = assign; // Checks against never430expectType<BASE>(test); // Finally check against the BASE type again431});432test("[obj, obj, TypedMap, List]", () => {433type T = { foo: { foo: TypedMap<{ bar: Immutable.List<BASE> }> } };434const getIn: GetIn<T> = STUB;435let test = getIn(["foo", "foo", "bar", 0]);436test = assign;437expectType<BASE>(test);438});439test("[obj, obj, TypedMap, Map]", () => {440type T = { foo: { foo: TypedMap<{ bar: Immutable.Map<string, BASE> }> } };441const getIn: GetIn<T> = STUB;442let test = getIn(["foo", "foo", "bar", "anystr"]);443test = assign; // Checks against never444expectType<BASE>(test); // Finally check against the BASE type again445});446});447448describe("List -> L4", () => {449test("[obj, obj, List, obj]", () => {450type T = { foo: { foo: Immutable.List<{ str: BASE }> } };451const getIn: GetIn<T> = STUB;452let test = getIn(["foo", "foo", 0, "str"]);453454test = assign; // Checks against never455expectType<BASE>(test); // Finally check against the BASE type again456});457test("[obj, obj, List, TypedMap]", () => {458type T = { foo: { foo: Immutable.List<TypedMap<{ str: BASE }>> } };459const getIn: GetIn<T> = STUB;460let test = getIn(["foo", "foo", 0, "str"]);461test = assign; // Checks against never462expectType<BASE>(test); // Finally check against the BASE type again463});464test("[obj, obj, List, List]", () => {465type T = { foo: { foo: Immutable.List<Immutable.List<BASE>> } };466const getIn: GetIn<T> = STUB;467let test = getIn(["foo", "foo", 0, 0]);468test = assign;469expectType<BASE>(test);470});471test("[obj, obj, List, Array]", () => {472type T = { foo: { foo: Immutable.List<BASE[]> } };473const getIn: GetIn<T> = STUB;474let test = getIn(["foo", "foo", 0, 0]);475test = assign;476expectType<BASE>(test);477});478test("[obj, obj, List, Map]", () => {479type T = { foo: { foo: Immutable.List<Immutable.Map<string, BASE>> } };480const getIn: GetIn<T> = STUB;481let test = getIn(["foo", "foo", 0, "anystr"]);482test = assign; // Checks against never483expectType<BASE>(test); // Finally check against the BASE type again484});485});486487describe("Map -> L4", () => {488test("[obj, obj, Map, obj]", () => {489type T = { foo: { foo: Immutable.Map<string, { str: BASE }> } };490const getIn: GetIn<T> = STUB;491let test = getIn(["foo", "foo", "anystr", "str"]);492test = assign; // Checks against never493expectType<BASE>(test); // Finally check against the BASE type again494});495test("[obj, obj, Map, TypedMap]", () => {496type T = { foo: { foo: Immutable.Map<string, TypedMap<{ str: BASE }>> } };497const getIn: GetIn<T> = STUB;498let test = getIn(["foo", "foo", "anystr", "str"]);499test = assign; // Checks against never500expectType<BASE>(test); // Finally check against the BASE type again501});502test("[obj, obj, Map, List]", () => {503type T = { foo: { foo: Immutable.Map<string, Immutable.List<BASE>> } };504const getIn: GetIn<T> = STUB;505let test = getIn(["foo", "foo", "anystr", 0]);506test = assign;507expectType<BASE>(test);508});509test("[obj, obj, Map, Array]", () => {510type T = { foo: { foo: Immutable.Map<string, BASE[]> } };511const getIn: GetIn<T> = STUB;512let test = getIn(["foo", "foo", "anystr", 0]);513test = assign;514expectType<BASE>(test);515});516test("[obj, obj, Map, Map]", () => {517type T = {518foo: { foo: Immutable.Map<string, Immutable.Map<string, BASE>> };519};520const getIn: GetIn<T> = STUB;521let test = getIn(["foo", "foo", "anystr", "anystr"]);522test = assign; // Checks against never523expectType<BASE>(test); // Finally check against the BASE type again524});525});526});527528529