mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-15 08:22:37 +01:00
Fix unit test
This commit is contained in:
@@ -9,7 +9,7 @@ import ExpressionResultView from './results/ExpressionResultView';
|
||||
import WhatsnewResult from '../models/WhatsnewResult';
|
||||
import WhatsnewResultView from './results/WhatsnewResultView';
|
||||
import ErrorResult from '../models/ErrorResult';
|
||||
import expression from '../../expression';
|
||||
import * as expression from '../expression';
|
||||
|
||||
export default class DisplayResult extends React.Component {
|
||||
render() {
|
||||
@@ -22,18 +22,6 @@ export default class DisplayResult extends React.Component {
|
||||
</div>;
|
||||
}
|
||||
|
||||
renderUnknown() {
|
||||
return <div className="result">
|
||||
<div className="error">¯\_(ツ)_/¯ Sorry, i don′t know what <strong>{this.props.input}</strong> is</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
renderError(message) {
|
||||
return <div className="result">
|
||||
<div className="error">(X_X) Error occurred: <strong>{message}</strong></div>
|
||||
</div>
|
||||
}
|
||||
|
||||
findResultComponent(result) {
|
||||
if(result instanceof HelpResult) {
|
||||
return <HelpResultView content={result} />
|
||||
@@ -51,14 +39,14 @@ export default class DisplayResult extends React.Component {
|
||||
return <WhatsnewResultView />
|
||||
}
|
||||
|
||||
if (result instanceof expression.ExpressionError) {
|
||||
return this.renderError(result.message);
|
||||
if (result instanceof ErrorResult) {
|
||||
return <div className="result">
|
||||
<div className="error">(X_X) Ooops.. Something ain' right: <strong>{result.error.message}</strong></div>
|
||||
</div>
|
||||
}
|
||||
|
||||
if (result instanceof Error) {
|
||||
return this.renderError(result.message);
|
||||
}
|
||||
|
||||
return this.renderUnknown();
|
||||
return <div className="result">
|
||||
<div className="error">¯\_(ツ)_/¯ Sorry, i don′t know what <strong>{this.props.input}</strong> is</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import Operand from './expression/operand';
|
||||
export { default as Operand } from './expression/operand';
|
||||
export { default as ExpressionError } from './expression/ExpressionError';
|
||||
|
||||
var expression = {
|
||||
factories:[],
|
||||
|
||||
@@ -72,7 +72,7 @@ export default class Operand {
|
||||
var parsed = numberParser.parse(input);
|
||||
|
||||
if(!parsed) {
|
||||
throw new ExpressionError("Unknown number: " + input);
|
||||
throw new ExpressionError(input + " is not a valid number");
|
||||
}
|
||||
|
||||
return new Operand(parsed);
|
||||
|
||||
@@ -30,28 +30,10 @@ describe('hash arguments parser', function() {
|
||||
expect(args.commands).toEqual(['clear', '16 15', '16&15']);
|
||||
});
|
||||
|
||||
it('should parse multiple commands url encoded', function() {
|
||||
var args = hash.getArgs('#' + encodeURI('1|2||1^2||~2'));
|
||||
expect(args).not.toBe(null);
|
||||
expect(args).toBeDefined();
|
||||
expect(args.commands).toEqual(['1|2', '1^2', '~2']);
|
||||
});
|
||||
|
||||
it('should parse multiple commands and switcher encoded', function() {
|
||||
it('should parse multiple commands encoded', function() {
|
||||
var args = hash.getArgs('#' + encodeURI('1|2||1^2||~2||-notrack||-debug'));
|
||||
expect(args).not.toBe(null);
|
||||
expect(args).toBeDefined();
|
||||
expect(args.commands).toEqual(['1|2', '1^2', '~2']);
|
||||
expect(args.notrack).toBe(true);
|
||||
expect(args.debug).toBe(true);
|
||||
});
|
||||
|
||||
it('should parse only switchers encoded', function() {
|
||||
var args = hash.getArgs('#' + encodeURI('-notrack||-debug'));
|
||||
expect(args).not.toBe(null);
|
||||
expect(args).toBeDefined();
|
||||
expect(args.commands).toEqual([]);
|
||||
expect(args.notrack).toBe(true);
|
||||
expect(args.debug).toBe(true);
|
||||
expect(args.commands).toEqual(['1|2', '1^2', '~2','-notrack','-debug']);
|
||||
});
|
||||
});
|
||||
@@ -4,15 +4,15 @@ var parser = expression.parser;
|
||||
describe("operand", function() {
|
||||
it("should be able to create opearand from positive binary string", function() {
|
||||
var input = "0b10";
|
||||
var op = new expression.Operand(input);
|
||||
var op = new expression.Operand.parse(input);
|
||||
expect(op.value).toBe(2);
|
||||
expect(op.kind).toBe('dec');
|
||||
expect(op.kind).toBe('bin');
|
||||
});
|
||||
|
||||
it("should be able to create opearand from negative binary string", function() {
|
||||
var input = "-0b10";
|
||||
var op = new expression.Operand(input);
|
||||
var op = new expression.Operand.parse(input);
|
||||
expect(op.value).toBe(-2);
|
||||
expect(op.kind).toBe('dec');
|
||||
expect(op.kind).toBe('bin');
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user