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


TypeScript mocks.createVariable函数代码示例

本文整理汇总了TypeScript中src/variables/mocks.createVariable函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createVariable函数的具体用法?TypeScript createVariable怎么用?TypeScript createVariable使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: it

    it(`should filter vars with shared prefix: ${example.name}`, () => {
      const target = createVariable('target', 'match me!')
      const partial = createVariable('tar', 'broke!')
      const vars = [example, target, partial]

      const actual = exportVariables([example], vars)

      expect(actual).toEqual([example, target])
    })
开发者ID:influxdata,项目名称:influxdb,代码行数:9,代码来源:exportVariables.test.ts

示例2: describe

describe('exportVariables', () => {
  it('should find dependent variables', () => {
    const a = createVariable('a', 'f(x: v.b)')
    const b = createVariable('b', 'cool')
    const c = createVariable('c', 'nooo!')

    const vars = [a, b, c]

    const actual = exportVariables([a], vars)

    expect(actual).toEqual([a, b])
  })

  it('should find dependent variables with cycles', () => {
    const a = createVariable('a', 'f(x: v.b, y: v.c)')
    const b = createVariable('b', 'f(x: v.f, y: v.e)')
    const c = createVariable('c', 'f(x: v.g)')
    const d = createVariable('d', 'nooooo!')
    const e = createVariable('e', 'pick')
    const f = createVariable('f', 'f(x: v.a, y: v.b)')
    const g = createVariable('g', 'yay')
    const h = createVariable('h', 'nooooo!')

    const vars = [a, b, c, d, e, f, g, h]

    const actual = exportVariables([a], vars)
    const expected = new Set([a, b, c, e, f, g])

    expect(new Set(actual)).toEqual(expected)
  })

  const examples = [
    createVariable('alone', 'v.target'),
    createVariable('space', '\tv.target\n'),
    createVariable('func', 'f(x: v.target)'),
    createVariable('brackets', '[v.target, other]'),
    createVariable('braces', '(v.target)'),
    createVariable('add', '1+v.target-2'),
    createVariable('mult', '1*v.target/2'),
    createVariable('mod', '1+v.target%2'),
    createVariable('bool', '1>v.target<2'),
    createVariable('assignment', 'x=v.target\n'),
    createVariable('curly', '{beep:v.target}\n'),
    createVariable('arrow', '(r)=>v.target==r.field\n'),
    createVariable('comment', '\nv.target//wat?'),
    createVariable('not equal', 'v.target!=r.field'),
    createVariable('like', 'other=~v.target'),
  ]

  examples.forEach(example => {
    it(`should filter vars with shared prefix: ${example.name}`, () => {
      const target = createVariable('target', 'match me!')
      const partial = createVariable('tar', 'broke!')
      const vars = [example, target, partial]

      const actual = exportVariables([example], vars)

      expect(actual).toEqual([example, target])
    })
  })
})
开发者ID:influxdata,项目名称:influxdb,代码行数:61,代码来源:exportVariables.test.ts

示例3: it

    it('converts a variable with dependencies to a template', () => {
      const a = {
        ...createVariable('a', 'x.b + 1'),
        labels: [myfavelabel],
      }
      const b = createVariable('b', '9000')
      const dependencies = [a, b]

      const actual = variableToTemplate(myVariable, dependencies)

      const expected = {
        meta: {
          version: '1',
          name: 'beep-Template',
          description: 'template created from variable: beep',
        },
        content: {
          data: {
            type: 'variable',
            id: '039ae3b3b74b0000',
            attributes: {
              name: 'beep',
              arguments: {
                type: 'query',
                values: {
                  query: 'f(x: v.a)',
                  language: 'flux',
                },
              },
              selected: null,
            },
            relationships: {
              variable: {
                data: [
                  {
                    id: 'a',
                    type: 'variable',
                  },
                  {
                    id: 'b',
                    type: 'variable',
                  },
                ],
              },
              label: {
                data: [],
              },
            },
          },
          included: [
            {
              type: 'variable',
              id: 'a',
              attributes: {
                name: 'a',
                arguments: {
                  type: 'query',
                  values: {
                    query: 'x.b + 1',
                    language: 'flux',
                  },
                },
                selected: [],
              },
              relationships: {
                label: {
                  data: [
                    {
                      type: 'label',
                      id: '1',
                    },
                  ],
                },
              },
            },
            {
              type: 'variable',
              id: 'b',
              attributes: {
                name: 'b',
                arguments: {
                  type: 'query',
                  values: {
                    query: '9000',
                    language: 'flux',
                  },
                },
                selected: [],
              },
              relationships: {
                label: {
                  data: [],
                },
              },
            },
            {
              id: '1',
              type: 'label',
              attributes: {
                name: '1label',
//.........这里部分代码省略.........
开发者ID:sebito91,项目名称:influxdb,代码行数:101,代码来源:resourceToTemplate.test.ts


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