当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Map.of方法代码示例

本文整理汇总了TypeScript中Immutable.Map.of方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.of方法的具体用法?TypeScript Map.of怎么用?TypeScript Map.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Immutable.Map的用法示例。


在下文中一共展示了Map.of方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

 it('accepts flattened pairs via of()', () => {
   var m: Map<any, any> = Map.of(1, 'a', 2, 'b', 3, 'c');
   expect(m.size).toBe(3);
   expect(m.get(1)).toBe('a');
   expect(m.get(2)).toBe('b');
   expect(m.get(3)).toBe('c');
 });
开发者ID:threehams,项目名称:immutable-js,代码行数:7,代码来源:Map.ts

示例2: describe

describe("formatter", () => {
  let priceMap = Map.of(
    215, Set(["mixed fruit", "bubble yum"]),
    275, Set(["french fries"]),
    335, Set(["side salad"]),
    355, Set(["hot wings"]),
    420, Set(["mozzarella sticks"]),
    580, Set(["sampler plate"])
  );

  let priceCombinations = Set([
    List([215, 215, 215, 215, 215, 215, 215]),
    List([215, 355, 355, 580])
  ]);

  let expectedResult = Set([
    Set(["7 orders of mixed fruit or bubble yum (at $2.15 each)."]),
    Set([
      "1 order of mixed fruit or bubble yum (at $2.15 each).",
      "1 order of mixed fruit or bubble yum (at $2.15 each).",
      "2 orders of hot wings (at $3.55 each).",
      "1 order of sampler plate (at $5.80 each)."
    ])
  ]);

  it("properly formats the supplied data", () => {
    let f = new Formatter(priceMap, priceCombinations);
    expect(f.getSentences().equals(expectedResult)).toBe(true);
  });
});
开发者ID:Ethan826,项目名称:tablexi-coding-challenge,代码行数:30,代码来源:formatter.spec.ts

示例3: InterpreterState

export const createInterpreter = (): InterpreterState => {
  const globalEnv: Scope = {
    name: '_global_',
    parent: undefined,
    environment: Map<string, any>()
  }

  return new InterpreterState({
    _done: false,
    _isReturned: false,
    _result: undefined,
    isRunning: true,
    frames: Stack.of(0),
    scopes: Map.of(0, globalEnv),
    errors: List(),
    value: undefined,
    node: undefined
  })
}
开发者ID:evansb,项目名称:source-toolchain,代码行数:19,代码来源:interpreter.ts

示例4: describe

describe("parser", () => {

  let testData = `$15.05
mixed fruit,$2.15
vanilla calamari,$2.15
french fries,$2.75
side salad,$3.35
hot wings,$3.55
mozzarella sticks,$4.20
sampler plate,$5.80`;

  let expectedResults = Map.of(
    215, Set(["mixed fruit", "vanilla calamari"]),
    275, Set(["french fries"]),
    335, Set(["side salad"]),
    355, Set(["hot wings"]),
    420, Set(["mozzarella sticks"]),
    580, Set(["sampler plate"])
  );

  it("can determine the desired price from test data", () => {
    let p = new Parser(testData);
    expect(p.getParserResults().desiredPrice).toBe(1505);
  });

  it("can create Set of food items from test data", () => {
    let p = new Parser(testData);
    expect(p.getParserResults().foodEntries.equals(expectedResults)).toEqual(true);
  });

  it("can parse imported data", () => {
    let data = fs.readFileSync("./spec/helpers/menu.txt", "utf-8");
    let p = new Parser(data);
    expect(p.getParserResults().foodEntries.equals(expectedResults)).toEqual(true);
  });

  it("can validate data", () => {
    expect(Parser.validateData(testData)).toBe(true);
  });
});
开发者ID:Ethan826,项目名称:tablexi-coding-challenge,代码行数:40,代码来源:parser.spec.ts

示例5: parseOneLine

 private parseOneLine(line: string): Map<number, string> {
   //                 food name vvvvv|comma|v$v|vvvvv price
   let match = line.match(/((?:\w| )+)(?:,)(?:\$)(.*)/);
   return Map.of(this.integerifyCash(match[2]), Set([match[1].trim()]));
 }
开发者ID:Ethan826,项目名称:tablexi-coding-challenge,代码行数:5,代码来源:parser.ts

示例6: expect

 expect(() => {
   Map.of(1, 2, 3);
 }).toThrow('Missing value for key: 3');
开发者ID:threehams,项目名称:immutable-js,代码行数:3,代码来源:Map.ts


注:本文中的Immutable.Map.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。