autorest.clicommon/test/test_directive_action_setPr...

68 строки
2.1 KiB
TypeScript
Исходник Постоянная ссылка Обычный вид История

2020-02-25 06:10:36 +03:00
import { assert } from 'chai';
import 'mocha';
import { ActionSet, ActionSetProperty } from '../src/plugins/modifier/cliDirectiveAction';
import { M4Node } from '../src/schema';
import { Metadata } from "@azure-tools/codemodel";
describe('Test Directive - Action - setProperty', function () {
2020-03-06 11:45:52 +03:00
var descriptor = {
parent: null,
targetIndex: -1,
target: null,
};
2020-02-25 06:10:36 +03:00
it('directive setProperty - string', () => {
let baseline = {
key: "someValue",
};
let action = new ActionSetProperty("someValue", "key", () => true);
2020-03-06 11:45:52 +03:00
descriptor.target = new Metadata();
action.process(descriptor);
assert.deepEqual(descriptor.target.language["cli"], baseline);
2020-02-25 06:10:36 +03:00
});
it('directive setProperty - bool', () => {
let baseline = {
key: true,
};
let action = new ActionSetProperty(true, "key", () => false);
2020-03-06 11:45:52 +03:00
descriptor.target = new Metadata();
action.process(descriptor);
assert.deepEqual(descriptor.target.language["cli"], baseline);
2020-02-25 06:10:36 +03:00
});
it('directive setProperty - undefined', () => {
let baseline = {
key: "someValue",
};
let action = new ActionSetProperty(undefined, "key", () => "someValue");
2020-03-06 11:45:52 +03:00
descriptor.target = new Metadata();
action.process(descriptor);
assert.deepEqual(descriptor.target.language["cli"], baseline);
2020-02-25 06:10:36 +03:00
});
it('directive setProperty - null', () => {
let baseline = {
key: "someValue",
};
let action = new ActionSetProperty(null, "key", () => "someValue");
2020-03-06 11:45:52 +03:00
descriptor.target = new Metadata();
action.process(descriptor);
assert.deepEqual(descriptor.target.language["cli"], baseline);
2020-02-25 06:10:36 +03:00
});
it('directive setProperty - array', () => {
let baseline = {
key: ['a','b','c'],
};
let action = new ActionSetProperty(['a', 'b', 'c'], "key", () => true);
2020-03-06 11:45:52 +03:00
descriptor.target = new Metadata();
action.process(descriptor);
assert.deepEqual(descriptor.target.language["cli"], baseline);
2020-02-25 06:10:36 +03:00
});
});