當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。