Skip to content

Whitespaces are not ignored #1

Open
@PhilippSalvisberg

Description

@PhilippSalvisberg

Hi Friedhold,

An interesting function. Thanks for sharing. I did a small test and found out that whitespaces are not ignored. Is there any reason to do so?

Here's my test using utPLSQL:

CREATE OR REPLACE PACKAGE test_get_codehash4cmp IS
   --%suite
   --%rollback(manual)

   --%beforeall
   PROCEDURE setup;
   
   --%afterall
   PROCEDURE teardown;

   --%test
   PROCEDURE test_ignore_nl;

   --%test
   PROCEDURE test_ignore_space;

END test_get_codehash4cmp;
/

CREATE OR REPLACE PACKAGE BODY test_get_codehash4cmp IS

   PROCEDURE setup IS
   BEGIN
      -- requires create procedure privilege granted directly to the user
      EXECUTE IMMEDIATE 'CREATE OR REPLACE PROCEDURE p1 IS BEGIN NULL; END;';
      EXECUTE IMMEDIATE 'CREATE OR REPLACE PROCEDURE p2 IS 
                             BEGIN 
                                NULL; 
                             END;';
      EXECUTE IMMEDIATE 'CREATE OR REPLACE PROCEDURE p3 IS BEGIN NULL;END;';
   END;
   
   PROCEDURE teardown IS
   BEGIN
      EXECUTE IMMEDIATE 'DROP PROCEDURE p1';
      EXECUTE IMMEDIATE 'DROP PROCEDURE p2';
      EXECUTE IMMEDIATE 'DROP PROCEDURE p3';
   END;

   PROCEDURE test_ignore_nl IS
   BEGIN
      ut.expect(get_codehash4cmp('P1')).to_equal(get_codehash4cmp('P2'));
   END test_ignore_nl;

   PROCEDURE test_ignore_space IS
   BEGIN
      ut.expect(get_codehash4cmp('P1')).to_equal(get_codehash4cmp('P3'));
   END test_ignore_space;
END test_get_codehash4cmp;
/

The test output is:

test_get_codehash4cmp
  test_ignore_nl [.014 sec] (FAILED - 1)
  test_ignore_space [.009 sec] (FAILED - 2)
 
Failures:
 
  1) test_ignore_nl
      Actual: 'D7582B235E3039360815D9FCFD1ABB9EFCF5885C5F87013B1DDA15F13B3AFF31B8E13B92519AAFDFCABC893B82019732' (varchar2) was expected to equal: '425D771E01089C67C4DAF1D9D36CA56DA4DB701CE66560A02B2BB9CC20A847FCCF1AB239DEC0EDC2EA6D0541D92C2A7D' (varchar2)
      at "SCOTT.TEST_GET_CODEHASH4CMP.TEST_IGNORE_NL", line 23 ut.expect(get_codehash4cmp('P1')).to_equal(get_codehash4cmp('P2'));
       
  2) test_ignore_space
      Actual: 'D7582B235E3039360815D9FCFD1ABB9EFCF5885C5F87013B1DDA15F13B3AFF31B8E13B92519AAFDFCABC893B82019732' (varchar2) was expected to equal: 'FE6A4ED2176F8D191B9DD8BF8281B2DFF20D1C73238F9169755236655E2168FEFDBF81243B28285DF0EA12DD9B035408' (varchar2)
      at "SCOTT.TEST_GET_CODEHASH4CMP.TEST_IGNORE_SPACE", line 28 ut.expect(get_codehash4cmp('P1')).to_equal(get_codehash4cmp('P3'));
       
Finished in .258925 seconds
2 tests, 2 failed, 0 errored, 0 disabled, 0 warning(s)

To get a better result the hash should be based on the relevant tokens produced by a lexer. Comments should probably also be excluded (of course hints and comments should different lexer tokens).

Thanks
Philipp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions