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

Different test result between ES6 import VerEx and local VerEx #203

Open
lfh19961021 opened this issue Sep 22, 2020 · 0 comments
Open

Different test result between ES6 import VerEx and local VerEx #203

lfh19961021 opened this issue Sep 22, 2020 · 0 comments

Comments

@lfh19961021
Copy link

lfh19961021 commented Sep 22, 2020

Hello,
I am using JSVerbalExpressions to extract the specified format of strings,
when the VerEx test() result returns true, some code will be implemented.

But I found a strange problem when I try to separate the format from a different file in ES6 style.

The following code is trying to import a file that included formats that represent in VerEx, then call the test() function from the imported Object variable.

In Format.js

import VerEx from 'verbal-expressions'

let testResult = VerEx().startOfLine().anythingBut('.').find('-').anything().then('.').anything().endOfLine().test('CT-CP-RF-03.CWS.TEMP.1')

export { testResult };
export default {
    Format01: {
        description: "Metadata with floor information and following [Lo-cat-ion].[element] rule",
        example: "AHU-S-3F-02.CHW.FLOW",
        separator_lv1: ".", 
        separator_lv2: ".",
        regExp: VerEx().startOfLine().anythingBut('.').find('-').anything().then('.').anything().endOfLine()
    },
    Format02: {
        description: "",
        example: "",
        separator_lv1: "", 
        separator_lv2: "",
        regExp: VerEx().startOfLine().anythingBut('.').maybe('-').anything().then(':').anythingBut('.-').endOfLine()
    },
}

I did many tests in the following file, between local define VerEx and import VerEx, including

  1. check regExp string
  2. test('Hardcode String') by local VerEx,
    test('Hardcode String') in import file local,
    test('Hardcode String') by import VerEx
  3. check parameter storing value equality before test()
    check parameter storing value equality after test()
  4. test(parameter) by local VerEx,
    test(parameter) by import VerEx <---- this is the problem

even some tricky thing like
5. force copy string var string_copy = (' ' + metadata).slice(1);

In formatter.js

import Format, {testResult} from './data/Format'

format(metadata) {
         //5.
        var string_copy = (' ' + metadata).slice(1);
        if(metadata == 'CT-CP-RF-03.CWS.TEMP.1'){

            //1. check regExp string
            //import regExp  /^(?:[^\.]*)(?:-)(?:.*)(?:\.)(?:.*)$/gm
            console.log('import regExp ',this.formatList.Format01.regExp);
            //local regExp  /^(?:[^\.]*)(?:-)(?:.*)(?:\.)(?:.*)$/gm
            console.log('local regExp ',VerEx().startOfLine().anythingBut('.').find('-').anything().then('.').anything().endOfLine());

            //2. 
            //local test("CT-CP-RF-03.CWS.TEMP.1"):  true
            console.log('local test("CT-CP-RF-03.CWS.TEMP.1"): ', VerEx().startOfLine().anythingBut('.').find('-').anything().then('.').anything().endOfLine().test('CT-CP-RF-03.CWS.TEMP.1'));
            //import local testResult("CT-CP-RF-03.CWS.TEMP.1"):  true
            console.log('import local testResult("CT-CP-RF-03.CWS.TEMP.1"): ', testResult);
            //import test("CT-CP-RF-03.CWS.TEMP.1"):  true
            console.log('import test("CT-CP-RF-03.CWS.TEMP.1"): ', this.formatList.Format01.regExp.test('CT-CP-RF-03.CWS.TEMP.1'));

            //3.
            //Before test():  CT-CP-RF-03.CWS.TEMP.1
            console.log('Before test(): ',metadata);
            //Before test():  true true
            console.log('Before test(): ',metadata == 'CT-CP-RF-03.CWS.TEMP.1', metadata === 'CT-CP-RF-03.CWS.TEMP.1');
            
            //4.
            //local test(metadata):  true
            console.log('local test(metadata): ',VerEx().startOfLine().anythingBut('.').find('-').anything().then('.').anything().endOfLine().test(metadata));
            //import test(metadata):  false
            console.log('import test(metadata): ',this.formatList.Format01.regExp.test(metadata));
            
            //3.
            //After test():  CT-CP-RF-03.CWS.TEMP.1
            console.log('After test(): ',metadata);
            //After test():  true true
            console.log('After test(): ',metadata == 'CT-CP-RF-03.CWS.TEMP.1', metadata === 'CT-CP-RF-03.CWS.TEMP.1');
        }

but when I try to use VerEx that import from the other file to test() the parameter (in 4.), it will return false although I checked it is equal with the hardcode string (not all of the parameter having this problem)

Test Case:
Tested hardcode string === parameter
Local VerEx + hardcode string = pass
Local VerEx + parameter = pass
Import VerEx + hardcode string = pass
Import VerEx + parameter = fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants