-
Notifications
You must be signed in to change notification settings - Fork 147
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
Add support for messageFormat strings containing conditionals #442
Changes from 2 commits
39feab1
2acc0fe
78578c5
b6894c6
8f22437
25eab67
44ac4c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,3 +222,29 @@ tap.test('#getPropertyValue', t => { | |
|
||
t.end() | ||
}) | ||
|
||
tap.test('#parseMessageFormat', t => { | ||
const logData = { | ||
level: 30, | ||
data1: { | ||
data2: 'bar' | ||
} | ||
} | ||
|
||
t.test('parseMessageFormat translates if / else statement to found property value', async t => { | ||
const log = fastCopy(logData) | ||
t.equal(internals.parseMessageFormat('{level} - {if data1.data2}{data1.data2}{end}', log), '{level} - bar') | ||
}) | ||
|
||
t.test('parseMessageFormat removes unescaped if statements', async t => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you mean non-terminated instead of unescaped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed wording. |
||
const log = fastCopy(logData) | ||
t.equal(internals.parseMessageFormat('{level} - {if data1.data2}{data1.data2}', log), '{level} - {data1.data2}') | ||
}) | ||
|
||
t.test('parseMessageFormat removes unescaped end statements', async t => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "floating" is a better term than "unescaped" here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed wording. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the format string is?:
(i.e. someone tried to add an unsupported nested condition but failed to add the leading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The additional |
||
const log = fastCopy(logData) | ||
t.equal(internals.parseMessageFormat('{level} - {data1.data2}{end}', log), '{level} - {data1.data2}') | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a few tests for not-matching if/else/end pair? What error would you get? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah for sure. Thanks for the fast code review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added further test scenarios. |
||
|
||
t.end() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a better name:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed accordingly.