From cfb3e246cd817c0de6d0327e37fa7223c5919696 Mon Sep 17 00:00:00 2001 From: boryslevytskyi Date: Sun, 28 May 2017 00:34:00 +0300 Subject: [PATCH] Code renames --- .../BitwiseOperationExpressionView.jsx | 2 +- .../models/BitwiseExpressionViewModel.js | 10 ++++----- src/app/expression.js | 8 +++---- ...randExpression.js => ExpressionOperand.js} | 14 ++++++------ tests/unit/expressionSpec.js | 22 +++++++++---------- 5 files changed, 28 insertions(+), 28 deletions(-) rename src/app/expression/{SingleOperandExpression.js => ExpressionOperand.js} (66%) diff --git a/src/app/components/results/BitwiseOperationExpressionView.jsx b/src/app/components/results/BitwiseOperationExpressionView.jsx index 42e5781..8a58379 100644 --- a/src/app/components/results/BitwiseOperationExpressionView.jsx +++ b/src/app/components/results/BitwiseOperationExpressionView.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Operand, ListOfNumbersExpression, SingleOperandExpression, MultipleOperandsExpression } from '../../expression'; +import { Operand, ListOfNumbersExpression, ExpressionOperand, MultipleOperandsExpression } from '../../expression'; import formatter from '../../formatter'; import BinaryStringView from './BinaryStringView'; import BitwiseExpressionViewModel from './models/BitwiseExpressionViewModel'; diff --git a/src/app/components/results/models/BitwiseExpressionViewModel.js b/src/app/components/results/models/BitwiseExpressionViewModel.js index e5588c7..5958ba9 100644 --- a/src/app/components/results/models/BitwiseExpressionViewModel.js +++ b/src/app/components/results/models/BitwiseExpressionViewModel.js @@ -1,4 +1,4 @@ -import { Operand, SingleOperandExpression } from '../../../expression'; +import { Operand, ExpressionOperand } from '../../../expression'; export default class BitwiseExpressionViewModel { @@ -74,12 +74,12 @@ export default class BitwiseExpressionViewModel { }; addExpression(expression) { - this.maxNumberOfBits = Math.max(expression.operand1.apply().getLengthInBits(), this.maxNumberOfBits); + this.maxNumberOfBits = Math.max(expression.operand.apply().getLengthInBits(), this.maxNumberOfBits); this.items.push({ sign: expression.sign, - label: this.getLabel(expression.operand1), - operand: expression.operand1, + label: this.getLabel(expression.operand), + operand: expression.operand, allowFlipBits: this.allowFlipBits }); }; @@ -87,7 +87,7 @@ export default class BitwiseExpressionViewModel { addShiftExpressionResult(expression, resultOperand) { this.maxNumberOfBits = Math.max(resultOperand.getLengthInBits(), this.maxNumberOfBits); this.items.push({ - sign: expression.sign + expression.operand1.toString(), + sign: expression.sign + expression.operand.toString(), css: 'expression-result', operand: resultOperand, allowFlipBits: false diff --git a/src/app/expression.js b/src/app/expression.js index b9d37c6..fc7d6a9 100644 --- a/src/app/expression.js +++ b/src/app/expression.js @@ -1,9 +1,9 @@ import Operand from './expression/Operand'; -import SingleOperandExpression from './expression/SingleOperandExpression' +import ExpressionOperand from './expression/ExpressionOperand' export { default as Operand } from './expression/Operand'; export { default as ExpressionError } from './expression/ExpressionError'; -export { default as SingleOperandExpression } from './expression/SingleOperandExpression'; +export { default as ExpressionOperand } from './expression/ExpressionOperand'; var expression = { factories:[], @@ -90,7 +90,7 @@ var expression = { var op = null; if(num.indexOf('~') == '0') { - op = new SingleOperandExpression(input, Operand.parse(num.substring(1)), '~'); + op = new ExpressionOperand(input, Operand.parse(num.substring(1)), '~'); } else { op = Operand.parse(num); @@ -99,7 +99,7 @@ var expression = { if(sign == null) { return op; } else { - return new SingleOperandExpression(input, op, sign); + return new ExpressionOperand(input, op, sign); } }, normalizeString: function (string) { diff --git a/src/app/expression/SingleOperandExpression.js b/src/app/expression/ExpressionOperand.js similarity index 66% rename from src/app/expression/SingleOperandExpression.js rename to src/app/expression/ExpressionOperand.js index e9ac7fe..51686c6 100644 --- a/src/app/expression/SingleOperandExpression.js +++ b/src/app/expression/ExpressionOperand.js @@ -1,9 +1,9 @@ import Operand from './Operand'; -export default class SingleOperandExpression { +export default class ExpressionOperand { constructor(expressionString, operand, sign) { this.expressionString = expressionString; - this.operand1 = operand; + this.operand = operand; this.sign = sign; this.isExpression = true; this.isShiftExpression = this.sign.indexOf('<') >= 0 || this.sign.indexOf('>')>= 0; @@ -11,7 +11,7 @@ export default class SingleOperandExpression { } apply(operand) { - if (operand instanceof SingleOperandExpression) { + if (operand instanceof ExpressionOperand) { console.error("value shouldnt be expression", value); throw new Error('value shouldnt be expression'); } @@ -20,21 +20,21 @@ export default class SingleOperandExpression { var str = ''; if(this.sign == '~'){ - str = '~' + this.operand1.apply().value; + str = '~' + this.operand.apply().value; } else { - str = operand.value + this.sign + this.operand1.apply().value; + str = operand.value + this.sign + this.operand.apply().value; } console.log('eval:' + str, this); const resultValue = eval(str); - var resultOp = Operand.create(eval(str), this.operand1.kind || this.operand1.operand1.kind); + var resultOp = Operand.create(eval(str), this.operand.kind || this.operand.operand.kind); console.log(resultValue, resultOp); return resultOp; }; toString() { - return this.sign + this.operand1.toString(); + return this.sign + this.operand.toString(); } } \ No newline at end of file diff --git a/tests/unit/expressionSpec.js b/tests/unit/expressionSpec.js index 4af791a..5a8cd25 100644 --- a/tests/unit/expressionSpec.js +++ b/tests/unit/expressionSpec.js @@ -11,16 +11,16 @@ describe("expression parser", function() { }); var expressionCases = { - "0x2>>1": { operand1: 2, operand2:1, "sign":">>", string:"0x2>>1" }, - "123|111": { operand1: 123, operand2:111, "sign":"|", string: "123|111" }, - "23^0x1": { operand1: 23, operand2:1, "sign":"^", string: "23^0x1" }, - "0xf>>0xa": { operand1: 15, operand2:10, "sign":">>", string:"0xf>>0xa" }, - "0x10&0x11": { operand1: 0x10, operand2:0x11, "sign":"&", string:"0x10&0x11" }, - "0x1a^11": { operand1: 0x1a, operand2:11, "sign":"^", string:"0x1a^11" }, - "0x1a>>>11": { operand1: 0x1a, operand2:11, "sign":">>>", string:"0x1a>>>11" }, - '~3': { operand1: 3, operand2: null, "sign":"~", string:"~3" }, - '~0xa': { operand1: 0xa, operand2: null, "sign":"~", string:"~0xa" }, - '~-0xa': { operand1: -0xa, operand2: null, "sign":"~", string:"~-0xa" } + "0x2>>1": { operand: 2, operand2:1, "sign":">>", string:"0x2>>1" }, + "123|111": { operand: 123, operand2:111, "sign":"|", string: "123|111" }, + "23^0x1": { operand: 23, operand2:1, "sign":"^", string: "23^0x1" }, + "0xf>>0xa": { operand: 15, operand2:10, "sign":">>", string:"0xf>>0xa" }, + "0x10&0x11": { operand: 0x10, operand2:0x11, "sign":"&", string:"0x10&0x11" }, + "0x1a^11": { operand: 0x1a, operand2:11, "sign":"^", string:"0x1a^11" }, + "0x1a>>>11": { operand: 0x1a, operand2:11, "sign":">>>", string:"0x1a>>>11" }, + '~3': { operand: 3, operand2: null, "sign":"~", string:"~3" }, + '~0xa': { operand: 0xa, operand2: null, "sign":"~", string:"~0xa" }, + '~-0xa': { operand: -0xa, operand2: null, "sign":"~", string:"~-0xa" } }; // TODO: update to support multiple expressions @@ -36,7 +36,7 @@ describe("expression parser", function() { // expect(actual).toBeDefined(); // expect(actual).not.toBe(null); // expect(actual.sign).toBe(expected.sign); - // expect(actual.operand1.value).toBe(expected.operand1); + // expect(actual.operand.value).toBe(expected.operand); // if(expected.operand2 != null) { // expect(actual.operand2.value).toBe(expected.operand2);