mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 17:23:19 -05:00
Cleanup nbformat, more common tests (#10311)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { isPrimitive } from 'sql/workbench/services/notebook/common/jsonext';
|
||||
|
||||
suite('jsonext', function (): void {
|
||||
test('Validate null object is primitive', async function (): Promise<void> {
|
||||
let object = null;
|
||||
assert.equal(isPrimitive(object), true, 'null object should be primitive');
|
||||
object = undefined;
|
||||
assert.equal(isPrimitive(object), false, 'undefined object should not be primitive');
|
||||
});
|
||||
test('Validate boolean types are primitive', async function (): Promise<void> {
|
||||
let object: boolean = false;
|
||||
assert.equal(isPrimitive(object), true, 'false boolean object should be primitive');
|
||||
object = true;
|
||||
assert.equal(isPrimitive(object), true, 'true boolean object should be primitive');
|
||||
});
|
||||
test('Validate number types are primitive', async function (): Promise<void> {
|
||||
let object: number = 0;
|
||||
assert.equal(isPrimitive(object), true, 'number with value 0 should be primitive');
|
||||
object = 1;
|
||||
assert.equal(isPrimitive(object), true, 'number with value 1 should be primitive');
|
||||
});
|
||||
test('Validate string types are primitive', async function (): Promise<void> {
|
||||
let object: string = '';
|
||||
assert.equal(isPrimitive(object), true, 'empty strings should be primitive');
|
||||
object = 'nonempty string';
|
||||
assert.equal(isPrimitive(object), true, 'non-empty strings should be primitive');
|
||||
});
|
||||
test('custom object is not primitive', async function (): Promise<void> {
|
||||
let object = {
|
||||
prop1: 'val1'
|
||||
};
|
||||
assert.equal(isPrimitive(object), false, 'custom object should not be primitive');
|
||||
object = undefined;
|
||||
assert.equal(isPrimitive(object), false, 'undefined object should not be primitive');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { nbformat } from 'sql/workbench/services/notebook/common/nbformat';
|
||||
import * as assert from 'assert';
|
||||
|
||||
suite('nbformat', function (): void {
|
||||
let sampleOutput: nbformat.IOutput = {
|
||||
data: undefined,
|
||||
ename: '',
|
||||
evalue: undefined,
|
||||
execution_count: 0,
|
||||
name: undefined,
|
||||
output_type: 'display_data'
|
||||
};
|
||||
test('Validate display_data Output Type', async function (): Promise<void> {
|
||||
sampleOutput.output_type = 'display_data';
|
||||
assert.equal(nbformat.isDisplayData(sampleOutput), true, 'display_data output type not recognized correctly');
|
||||
assert.equal(nbformat.isDisplayUpdate(sampleOutput), false, 'update_display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isError(sampleOutput), false, 'error output type incorrectly recognized');
|
||||
assert.equal(nbformat.isExecuteResult(sampleOutput), false, 'execute_result output type incorrectly recognized');
|
||||
assert.equal(nbformat.isStream(sampleOutput), false, 'stream output type incorrectly recognized');
|
||||
});
|
||||
test('Validate update_display_data Output Type', async function (): Promise<void> {
|
||||
sampleOutput.output_type = 'update_display_data';
|
||||
assert.equal(nbformat.isDisplayData(sampleOutput), false, 'display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isDisplayUpdate(sampleOutput), true, 'update_display_data output type not recognized correctly');
|
||||
assert.equal(nbformat.isError(sampleOutput), false, 'error output type incorrectly recognized');
|
||||
assert.equal(nbformat.isExecuteResult(sampleOutput), false, 'execute_result output type incorrectly recognized');
|
||||
assert.equal(nbformat.isStream(sampleOutput), false, 'stream output type incorrectly recognized');
|
||||
});
|
||||
test('Validate error Output Type', async function (): Promise<void> {
|
||||
sampleOutput.output_type = 'error';
|
||||
assert.equal(nbformat.isDisplayData(sampleOutput), false, 'display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isDisplayUpdate(sampleOutput), false, 'update_display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isError(sampleOutput), true, 'error output type not recognized correctly');
|
||||
assert.equal(nbformat.isExecuteResult(sampleOutput), false, 'execute_result output type incorrectly recognized');
|
||||
assert.equal(nbformat.isStream(sampleOutput), false, 'stream output type incorrectly recognized');
|
||||
});
|
||||
test('Validate execute_result Output Type', async function (): Promise<void> {
|
||||
sampleOutput.output_type = 'execute_result';
|
||||
assert.equal(nbformat.isDisplayData(sampleOutput), false, 'display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isDisplayUpdate(sampleOutput), false, 'update_display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isError(sampleOutput), false, 'error output type incorrectly recognized');
|
||||
assert.equal(nbformat.isExecuteResult(sampleOutput), true, 'execute_result output type not recognized correctly');
|
||||
assert.equal(nbformat.isStream(sampleOutput), false, 'stream output type incorrectly recognized');
|
||||
});
|
||||
test('Validate stream Output Type', async function (): Promise<void> {
|
||||
sampleOutput.output_type = 'stream';
|
||||
assert.equal(nbformat.isDisplayData(sampleOutput), false, 'display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isDisplayUpdate(sampleOutput), false, 'update_display_data output type incorrectly recognized');
|
||||
assert.equal(nbformat.isError(sampleOutput), false, 'error output type incorrectly recognized');
|
||||
assert.equal(nbformat.isExecuteResult(sampleOutput), false, 'execute_result output type incorrectly recognized');
|
||||
assert.equal(nbformat.isStream(sampleOutput), true, 'stream output type not recognized correctly');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user