Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle blob and numbers when parsing the value of 'this' object #558

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ export class LogContextUtil {
const valueSplit = value.split('.');
return valueSplit.length > 1 ? valueSplit[valueSplit.length - 1] : value;
}

public surroundBlobsWithQuotes(value: string): string {
return value.replace(/(BLOB\(\d+ bytes\))/g, '"$1"');
}

public removeQuotesFromBlob(value: string): string {
return value.replace(/'(BLOB\(\d+ bytes\))'/g, '$1');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class VariableAssignmentState implements DebugLogState {
logContext: LogContext
) {
try {
value = logContext.getUtil().surroundBlobsWithQuotes(value);
const obj = JSON.parse(value);
Object.keys(obj).forEach(key => {
const refContainer = logContext.getRefsMap().get(String(obj[key]))!;
Expand All @@ -169,6 +170,9 @@ export class VariableAssignmentState implements DebugLogState {
let varValue = obj[key];
if (typeof varValue === 'string') {
varValue = "'" + varValue + "'";
varValue = logContext.getUtil().removeQuotesFromBlob(varValue);
} else {
varValue = `${varValue}`;
}
container.variables.set(
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ describe('Variable assignment event', () => {
'staticInteger'
);
expect(
context.getStaticVariablesClassMap().get('signature')!.get(
'staticInteger'
)
context
.getStaticVariablesClassMap()
.get('signature')!
.get('staticInteger')
).to.include({
name: 'staticInteger',
value: 'null'
Expand All @@ -91,9 +92,10 @@ describe('Variable assignment event', () => {
'staticInteger'
);
expect(
context.getStaticVariablesClassMap().get('signature')!.get(
'staticInteger'
)
context
.getStaticVariablesClassMap()
.get('signature')!
.get('staticInteger')
).to.include({
name: 'staticInteger',
value: '5'
Expand Down Expand Up @@ -127,7 +129,7 @@ describe('Variable assignment event', () => {
const LOCAL_NESTED_VARIABLE_SCOPE_BEGIN =
'fakeTime|VARIABLE_SCOPE_BEGIN|[8]|this|NestedClass|true|false';
const LOCAL_NESTED_VARIABLE_ASSIGNMENT = `fakeTime|VARIABLE_ASSIGNMENT|[8]|this|{}|${DUMMY_REF}`;
const LOCAL_NESTED_JSON_VARIABLE_ASSIGNMENT = `fakeTime|VARIABLE_ASSIGNMENT|[8]|this|{"a":"0x37e2e22e","m":"0xff6e2ff","s":"MyObject.s"}|${DUMMY_REF}`;
const LOCAL_NESTED_JSON_VARIABLE_ASSIGNMENT = `fakeTime|VARIABLE_ASSIGNMENT|[8]|this|{"a":"0x37e2e22e","b1":BLOB(5 bytes),"b2":BLOB(50 bytes),"d":3.14,"m":"0xff6e2ff","s":"MyObject.s"}|${DUMMY_REF}`;
const LOCAL_NESTED_INNER_VARIABLE_ASSIGNMENT = `fakeTime|VARIABLE_ASSIGNMENT|[12]|this.s|"MyObject.s"|${DUMMY_REF}`;
const LOCAL_NESTED_JSON_INNER_VARIABLE_ASSIGNMENT = `fakeTime|VARIABLE_ASSIGNMENT|[10]|this.a|{"Name":"MyObjectAccount"}|${DUMMY_REF}`;
beforeEach(() => {
Expand Down Expand Up @@ -216,13 +218,27 @@ describe('Variable assignment event', () => {
state.handle(context);
expect(container.value).to.equal('');
expect(container.variablesRef).to.not.equal(0);
expect(container.variables).to.have.keys(['a', 'm', 's']);
const VAR_VALUES = ['0x37e2e22e', '0xff6e2ff', 'MyObject.s'];
['a', 'm', 's'].forEach((element, index) => {
expect(container.variables).to.have.keys([
'a',
'b1',
'b2',
'd',
'm',
's'
]);
const VAR_VALUES = [
"'0x37e2e22e'",
'BLOB(5 bytes)',
'BLOB(50 bytes)',
'3.14',
"'0xff6e2ff'",
"'MyObject.s'"
];
['a', 'b1', 'b2', 'd', 'm', 's'].forEach((element, index) => {
const innerContainer = container.variables.get(
element
) as ApexVariableContainer;
expect(innerContainer.value).to.equal(`'${VAR_VALUES[index]}'`);
expect(innerContainer.value).to.equal(`${VAR_VALUES[index]}`);
expect(innerContainer.variables).to.be.empty;
expect(innerContainer.variablesRef).to.equal(0);
});
Expand Down