version bump 0.4.0
- added missing bitshift (fixes #5) - brute-force unicode tests
This commit is contained in:
parent
74dda6db02
commit
79a265b662
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
node_modules
|
||||
test_files/*.py
|
||||
test_files/*.js
|
||||
test_files/baseline*
|
||||
misc/coverage.html
|
||||
misc/*/
|
||||
|
@ -3,8 +3,12 @@ misc/
|
||||
perf/
|
||||
bits/
|
||||
ctest/
|
||||
test_files/
|
||||
test.js
|
||||
.travis.yml
|
||||
.jscs.json
|
||||
.jshintrc
|
||||
.flowconfig
|
||||
.npmignore
|
||||
perf.txt
|
||||
Makefile
|
||||
|
@ -8,6 +8,7 @@ node_js:
|
||||
before_install:
|
||||
- "npm install -g npm@next"
|
||||
- "npm install -g mocha crc-32 benchmark ansi"
|
||||
- "npm install codepage"
|
||||
- "npm install blanket"
|
||||
- "npm install coveralls mocha-lcov-reporter"
|
||||
after_success:
|
||||
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (C) 2014 SheetJS
|
||||
Copyright (C) 2014-present SheetJS
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
11
Makefile
11
Makefile
@ -20,11 +20,11 @@ bits/01_version.js: package.json
|
||||
echo "CRC32.version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
clean: clean-baseline
|
||||
rm -f $(TARGET)
|
||||
|
||||
.PHONY: test mocha
|
||||
test mocha: test.js
|
||||
test mocha: test.js $(TARGET) baseline
|
||||
mocha -R spec -t 20000
|
||||
|
||||
.PHONY: ctest
|
||||
@ -70,3 +70,10 @@ perf:
|
||||
.PHONY: perf-all
|
||||
perf-all:
|
||||
bash misc/perf.sh
|
||||
|
||||
.PHONY: baseline clean-baseline
|
||||
baseline:
|
||||
./misc/make_baseline.sh
|
||||
|
||||
clean-baseline:
|
||||
rm -f test_files/*.*
|
||||
|
@ -51,6 +51,9 @@ For example:
|
||||
To run the in-browser tests, run a local server and go to the `ctest` directory.
|
||||
To update the browser artifacts, run `make ctest`.
|
||||
|
||||
`make baseline` will generate baseline files based on the unicode mapping at
|
||||
<http://mathias.html5.org>
|
||||
|
||||
## License
|
||||
|
||||
Please consult the attached LICENSE file for details. All rights not explicitly
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* crc32.js (C) 2014-2015 SheetJS -- http://sheetjs.com */
|
||||
/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
||||
/* vim: set ts=2: */
|
||||
var CRC32;
|
||||
/*:: declare var DO_NOT_EXPORT_CRC: any; */
|
||||
@ -14,7 +14,7 @@ var CRC32;
|
||||
return module;
|
||||
});
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
|
@ -1 +1 @@
|
||||
CRC32.version = '0.3.0';
|
||||
CRC32.version = '0.4.0';
|
||||
|
@ -51,7 +51,7 @@ function crc32_str(str/*:string*/)/*:CRC32Type*/ {
|
||||
c = (c&1023)+64; d = str.charCodeAt(i++) & 1023;
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (240|((c>>8)&7))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((c>>2)&63))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|(c&3))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|((c&3)<<4))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|(d&63))) & 0xFF];
|
||||
} else {
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (224|((c>>12)&15))) & 0xFF];
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* crc32.js (C) 2014-2015 SheetJS -- http://sheetjs.com */
|
||||
/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
||||
/* vim: set ts=2: */
|
||||
var CRC32;
|
||||
/*:: declare var DO_NOT_EXPORT_CRC: any; */
|
||||
@ -14,13 +14,13 @@ var CRC32;
|
||||
return module;
|
||||
});
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
}(function(CRC32) {
|
||||
CRC32.version = '0.3.0';
|
||||
CRC32.version = '0.4.0';
|
||||
/*::
|
||||
type CRC32Type = number;
|
||||
type ABuf = Array<number> | Buffer;
|
||||
@ -100,7 +100,7 @@ function crc32_str(str/*:string*/)/*:CRC32Type*/ {
|
||||
c = (c&1023)+64; d = str.charCodeAt(i++) & 1023;
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (240|((c>>8)&7))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((c>>2)&63))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|(c&3))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|((c&3)<<4))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|(d&63))) & 0xFF];
|
||||
} else {
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (224|((c>>12)&15))) & 0xFF];
|
||||
|
8
crc32.js
8
crc32.js
@ -1,4 +1,4 @@
|
||||
/* crc32.js (C) 2014-2015 SheetJS -- http://sheetjs.com */
|
||||
/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
||||
/* vim: set ts=2: */
|
||||
var CRC32;
|
||||
(function (factory) {
|
||||
@ -12,13 +12,13 @@ var CRC32;
|
||||
return module;
|
||||
});
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
}(function(CRC32) {
|
||||
CRC32.version = '0.3.0';
|
||||
CRC32.version = '0.4.0';
|
||||
/* see perf/crc32table.js */
|
||||
function signed_crc_table() {
|
||||
var c = 0, table = new Array(256);
|
||||
@ -93,7 +93,7 @@ function crc32_str(str) {
|
||||
c = (c&1023)+64; d = str.charCodeAt(i++) & 1023;
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (240|((c>>8)&7))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((c>>2)&63))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|(c&3))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|((c&3)<<4))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|(d&63))) & 0xFF];
|
||||
} else {
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (224|((c>>12)&15))) & 0xFF];
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* crc32.js (C) 2014-2015 SheetJS -- http://sheetjs.com */
|
||||
/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
||||
/* vim: set ts=2: */
|
||||
var CRC32;
|
||||
(function (factory) {
|
||||
@ -12,13 +12,13 @@ var CRC32;
|
||||
return module;
|
||||
});
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
} else {
|
||||
factory(CRC32 = {});
|
||||
}
|
||||
}(function(CRC32) {
|
||||
CRC32.version = '0.3.0';
|
||||
CRC32.version = '0.4.0';
|
||||
/* see perf/crc32table.js */
|
||||
function signed_crc_table() {
|
||||
var c = 0, table = new Array(256);
|
||||
@ -93,7 +93,7 @@ function crc32_str(str) {
|
||||
c = (c&1023)+64; d = str.charCodeAt(i++) & 1023;
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (240|((c>>8)&7))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((c>>2)&63))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|(c&3))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|((c&3)<<4))) & 0xFF];
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (128|(d&63))) & 0xFF];
|
||||
} else {
|
||||
crc = (crc >>> 8) ^ table[(crc ^ (224|((c>>12)&15))) & 0xFF];
|
||||
|
@ -5,8 +5,11 @@ if(typeof require !== 'undefined') {
|
||||
describe('source',function(){it('should load',function(){X=require('./');});});
|
||||
bits = require('./misc/bits.js');
|
||||
crc32table = require('./misc/table.js');
|
||||
fs = require("fs");
|
||||
} else { X = CRC32; }
|
||||
|
||||
function readlines(f) { return fs.readFileSync(f, "ascii").split("\n").filter(function(f) { return !!f; }); }
|
||||
|
||||
describe('crc32 table', function() {
|
||||
it('should match fixed table', function() {
|
||||
var badness = 0;
|
||||
@ -30,4 +33,20 @@ describe('crc32 bits', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if(typeof require !== 'undefined') describe("unicode", function() {
|
||||
if(!fs.existsSync("./test_files/uccat.txt")) return;;
|
||||
var uccat = readlines("./test_files/uccat.txt");
|
||||
uccat.forEach(function(cat) {
|
||||
it("Category " + cat, function() {
|
||||
if(!fs.existsSync("./test_files/baseline." + cat + ".txt")) return;
|
||||
var corpus = readlines("./test_files/baseline." + cat + ".txt");
|
||||
var uctable = require("./test_files/uctable." + cat + ".js");
|
||||
uctable.forEach(function(c, i) {
|
||||
/* since the baselines are passed via utf8, discard invalid codes */
|
||||
if(c.charCodeAt(0) >= 0xD800 && c.charCodeAt(0) < 0xE000) return;
|
||||
var cc = corpus[i], dd = X.str(c);
|
||||
assert.equal(dd, cc, ":" + i + ":" + c + ":" + cc + ":" + dd);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
39
misc/make_baseline.sh
Executable file
39
misc/make_baseline.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
# make_baseline.sh -- generate baselines for tests
|
||||
# Copyright (C) 2016-present SheetJS
|
||||
OUTD=../test_files
|
||||
CATURL=https://mathias.html5.org/data/unicode/8.0.0/categories/
|
||||
CATF=$OUTD/uccat.txt
|
||||
|
||||
ECHORED() { echo -ne '\x1B[0;31m'; echo -n $1; echo -ne '\x1B[0m'; echo; }
|
||||
|
||||
if [ -d misc ]; then cd misc; fi
|
||||
mkdir -p $OUTD
|
||||
if [ ! -e $CATF ]; then curl "$CATURL" | grep "code-points" | sed 's/.*="//g;s/-.*//g' > $CATF; fi
|
||||
|
||||
while read line; do
|
||||
JSF=uctable.${line}.js
|
||||
PYF=uctable_${line}.py
|
||||
BLF=baseline.${line}.txt
|
||||
JSURL="https://mathias.html5.org/data/unicode/format?version=8.0.0&category=${line}&type=symbols&prepend=var+unicode%20%3D%20&append=%3Bif(typeof%20module%20!%3D%3D%20'undefined')%20module.exports%20%3D%20unicode%3B"
|
||||
if [[ ! -e $OUTD/$JSF || ! -e $OUTD/$PYF || ! -e $OUTD/$BLF ]]; then
|
||||
ECHORED "Processing ${line}"
|
||||
if [ ! -e $JSF ]; then
|
||||
rm -f $PYF $BLF ${PYF}c
|
||||
echo "Downloading JS"
|
||||
</dev/null curl -o $JSF "$JSURL"
|
||||
fi
|
||||
if [ ! -e $PYF ]; then
|
||||
echo "Building Python script"
|
||||
rm -f $BLF ${PYF}c
|
||||
</dev/null node make_unicode_crc.njs ${line} | sed 's/\[ \[/uctable = \[ \[/' > $PYF
|
||||
fi
|
||||
if [ ! -e $BLF ]; then
|
||||
echo "Building Baseline text"
|
||||
python make_unicode_crc.py ${line} > baseline.${line}.txt
|
||||
fi
|
||||
for i in $JSF $PYF $BLF; do if [ -e $i ]; then mv $i $OUTD/; fi; done
|
||||
rm -f uctable_${line}.pyc
|
||||
fi
|
||||
done < $CATF
|
||||
|
5
misc/make_unicode_crc.njs
Normal file
5
misc/make_unicode_crc.njs
Normal file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
argv = process.argv.slice(2);
|
||||
var enc = require('codepage').utils.encode;
|
||||
function arr(x) { return [].slice.call(enc(65001, x)); }
|
||||
console.log(require('./uctable.' + argv[0]).map(arr));
|
19
misc/make_unicode_crc.py
Normal file
19
misc/make_unicode_crc.py
Normal file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
# make_unicode_crc.py -- generate baselines for tests
|
||||
# Copyright (C) 2016-present SheetJS
|
||||
|
||||
from zlib import crc32
|
||||
from array import array
|
||||
from sys import argv, stderr, exit
|
||||
from importlib import import_module
|
||||
|
||||
args = argv[1:]
|
||||
|
||||
if len(args) < 1:
|
||||
print >>stderr, "usage: " + argv[0] + " <category>"
|
||||
exit(1)
|
||||
|
||||
uctable = import_module("uctable_" + args[0]).uctable
|
||||
|
||||
for z in uctable:
|
||||
print crc32(array('B', z));
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# spin.sh -- show a spinner (for coverage test)
|
||||
# Copyright (C) 2014 SheetJS
|
||||
# Copyright (C) 2014-present SheetJS
|
||||
|
||||
wpid=$1
|
||||
delay=1
|
||||
|
@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "crc-32",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"author": "sheetjs",
|
||||
"description": "Pure-JS CRC-32",
|
||||
"keywords": [ "crc32", "checksum", "crc" ],
|
||||
"main": "./crc32",
|
||||
"devDependencies": {
|
||||
"codepage":"",
|
||||
"mocha":"",
|
||||
"uglify-js":""
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* bm.js (C) 2014 SheetJS -- http://sheetjs.com */
|
||||
/* bm.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
||||
var Benchmark = require('benchmark');
|
||||
var c = require('ansi')(process.stdout);
|
||||
|
||||
|
21
test.js
21
test.js
@ -5,8 +5,11 @@ if(typeof require !== 'undefined') {
|
||||
describe('source',function(){it('should load',function(){X=require('./');});});
|
||||
bits = require('./misc/bits.js');
|
||||
crc32table = require('./misc/table.js');
|
||||
fs = require("fs");
|
||||
} else { X = CRC32; }
|
||||
|
||||
function readlines(f) { return fs.readFileSync(f, "ascii").split("\n").filter(function(f) { return !!f; }); }
|
||||
|
||||
describe('crc32 table', function() {
|
||||
it('should match fixed table', function() {
|
||||
var badness = 0;
|
||||
@ -30,4 +33,20 @@ describe('crc32 bits', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if(typeof require !== 'undefined') describe("unicode", function() {
|
||||
if(!fs.existsSync("./test_files/uccat.txt")) return;;
|
||||
var uccat = readlines("./test_files/uccat.txt");
|
||||
uccat.forEach(function(cat) {
|
||||
it("Category " + cat, function() {
|
||||
if(!fs.existsSync("./test_files/baseline." + cat + ".txt")) return;
|
||||
var corpus = readlines("./test_files/baseline." + cat + ".txt");
|
||||
var uctable = require("./test_files/uctable." + cat + ".js");
|
||||
uctable.forEach(function(c, i) {
|
||||
/* since the baselines are passed via utf8, discard invalid codes */
|
||||
if(c.charCodeAt(0) >= 0xD800 && c.charCodeAt(0) < 0xE000) return;
|
||||
var cc = corpus[i], dd = X.str(c);
|
||||
assert.equal(dd, cc, ":" + i + ":" + c + ":" + cc + ":" + dd);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
38
test_files/uccat.txt
Normal file
38
test_files/uccat.txt
Normal file
@ -0,0 +1,38 @@
|
||||
C
|
||||
Cc
|
||||
Cf
|
||||
Cn
|
||||
Co
|
||||
Cs
|
||||
L
|
||||
LC
|
||||
Ll
|
||||
Lm
|
||||
Lo
|
||||
Lt
|
||||
Lu
|
||||
M
|
||||
Mc
|
||||
Me
|
||||
Mn
|
||||
N
|
||||
Nd
|
||||
Nl
|
||||
No
|
||||
P
|
||||
Pc
|
||||
Pd
|
||||
Pe
|
||||
Pf
|
||||
Pi
|
||||
Po
|
||||
Ps
|
||||
S
|
||||
Sc
|
||||
Sk
|
||||
Sm
|
||||
So
|
||||
Z
|
||||
Zl
|
||||
Zp
|
||||
Zs
|
Loading…
Reference in New Issue
Block a user