Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alexandra Rogova
jio_mebibou
Commits
c8334d54
Commit
c8334d54
authored
Aug 31, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test Query: drop require usage
parent
4b8bddba
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
155 additions
and
196 deletions
+155
-196
test/queries/key-jiodate.tests.js
test/queries/key-jiodate.tests.js
+15
-22
test/queries/key-schema.tests.js
test/queries/key-schema.tests.js
+25
-31
test/queries/key-typechecks.tests.js
test/queries/key-typechecks.tests.js
+8
-17
test/queries/key.tests.js
test/queries/key.tests.js
+96
-109
test/queries/tests.js
test/queries/tests.js
+11
-17
No files found.
test/queries/key-jiodate.tests.js
View file @
c8334d54
...
...
@@ -17,29 +17,20 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, jIO, jiodate, window, test,
ok, equal, deepEqual, sinon, start, stop, RSVP */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
require
(
'
jio
'
),
require
(
'
jiodate
'
));
}
module
(
jIO
,
jiodate
);
}([
'
jio
'
,
'
jiodate
'
,
'
qunit
'
],
function
(
jIO
,
jiodate
)
{
/*global jiodate*/
(
function
(
jIO
,
jiodate
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
,
module
=
QUnit
.
module
,
noop
=
function
()
{
return
;
// use with RSVP.all
};
module
(
'
Custom Key Queries with JIODate
'
);
var
noop
=
function
()
{
return
;
// use with RSVP.all
};
test
(
'
Stock comparison operators with year precision
'
,
function
()
{
var
docList
=
function
()
{
return
[
...
...
@@ -172,7 +163,8 @@
jIO
.
QueryFactory
.
create
(
qs
,
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
expected
,
"
Match with '
"
+
qs
+
"
' (parsed query string)
"
);
deepEqual
(
dl
,
expected
,
"
Match with '
"
+
qs
+
"
' (parsed query string)
"
);
})
);
});
...
...
@@ -190,7 +182,8 @@
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
],
"
Match with an invalid parsed string
"
+
qs
+
"
should return empty list but not raise errors
"
);
],
"
Match with an invalid parsed string
"
+
qs
+
"
should return empty list but not raise errors
"
);
})
);
});
...
...
@@ -198,4 +191,4 @@
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
}));
}
(
jIO
,
jiodate
));
test/queries/key-schema.tests.js
View file @
c8334d54
...
...
@@ -17,38 +17,29 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 100, nomen: true, vars: true */
/*global define, exports, require, module, jIO, window, test, ok,
deepEqual, sinon, start, stop, RSVP, jiodate */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
require
(
'
jio
'
),
require
(
'
jiodate
'
));
}
module
(
jIO
,
jiodate
);
}([
'
jio
'
,
'
jiodate
'
,
'
qunit
'
],
function
(
jIO
,
jiodate
)
{
/*global jiodate*/
(
function
(
jIO
,
jiodate
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
,
module
=
QUnit
.
module
,
noop
=
function
()
{
return
;
// use with RSVP.all
},
translationEqualityMatcher
=
function
(
data
)
{
return
function
(
object_value
,
value
)
{
value
=
data
[
value
];
return
(
object_value
===
value
);
};
},
key_schema
;
module
(
'
Custom Key Queries with Schema
'
);
var
noop
=
function
()
{
return
;
// use with RSVP.all
};
var
translationEqualityMatcher
=
function
(
data
)
{
return
function
(
object_value
,
value
)
{
value
=
data
[
value
];
return
(
object_value
===
value
);
};
};
/*jslint unparam: true*/
var
key_schema
=
{
key_schema
=
{
cast_lookup
:
{
dateType
:
function
(
obj
)
{
return
new
jiodate
.
JIODate
(
obj
);
...
...
@@ -330,7 +321,8 @@
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
Key Schema: It should be possible to look for a translated string
'
);
],
'
Key Schema: It should be possible to look for a translated
'
+
'
string
'
);
})
);
...
...
@@ -345,7 +337,8 @@
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
Key Schema: It should be possible to look for a translated string with operator =
'
);
],
'
Key Schema: It should be possible to look for a translated
'
+
'
string with operator =
'
);
})
);
...
...
@@ -360,9 +353,10 @@
// }).exec(doc_list);
// deepEqual(doc_list, [
// {'identifier': '2', 'state': 'closed'}
// ], 'Key Schema: It should be possible to look for a translated string with operator !=');
// ], 'Key Schema: It should be possible to look for a translated ' +
// 'string with operator !=');
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
}));
}
(
jIO
,
jiodate
));
test/queries/key-typechecks.tests.js
View file @
c8334d54
...
...
@@ -17,22 +17,12 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 90, nomen: true */
/*global define, exports, require, module, jIO, window, test,
raises, ok, equal, deepEqual, sinon */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
require
(
'
jio
'
));
}
module
(
jIO
);
}([
'
jio
'
,
'
qunit
'
],
function
(
jIO
)
{
(
function
(
jIO
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
equal
=
QUnit
.
equal
,
ok
=
QUnit
.
ok
,
module
=
QUnit
.
module
;
module
(
'
Key and key_schema objects validation
'
);
...
...
@@ -53,7 +43,8 @@
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
"
QueryFactory.create(): Argument 1 is not a search text or a parsable object
"
,
"
QueryFactory.create(): Argument 1 is not a search text or a
"
+
"
parsable object
"
,
'
wrong exception message
'
);
}
...
...
@@ -139,4 +130,4 @@
}
});
}));
}
(
jIO
));
test/queries/key.tests.js
View file @
c8334d54
...
...
@@ -17,28 +17,58 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, jIO, window, test, ok,
equal, deepEqual, sinon, stop, start, RSVP, jiodate */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
require
(
'
jio
'
),
require
(
'
jiodate
'
));
}
module
(
jIO
,
jiodate
);
}([
'
jio
'
,
'
jiodate
'
,
'
qunit
'
],
function
(
jIO
,
jiodate
)
{
/*global jiodate*/
(
function
(
jIO
,
jiodate
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
equal
=
QUnit
.
equal
,
deepEqual
=
QUnit
.
deepEqual
,
module
=
QUnit
.
module
,
noop
=
function
()
{
return
;
// use with RSVP.all
},
dateCast
=
function
(
obj
)
{
return
new
jiodate
.
JIODate
(
obj
);
},
translationEqualityMatcher
=
function
(
data
)
{
return
function
(
object_value
,
value
)
{
value
=
data
[
value
];
return
(
object_value
===
value
);
};
},
// This method is provided as an example.
// A more robust solution to manage diacritics is recommended for production
// environments, with unicode normalization, like (untested):
// https://github.com/walling/unorm/
accentFold
=
function
(
s
)
{
var
map
=
[
[
new
RegExp
(
'
[àáâãäå]
'
,
'
gi
'
),
'
a
'
],
[
new
RegExp
(
'
æ
'
,
'
gi
'
),
'
ae
'
],
[
new
RegExp
(
'
ç
'
,
'
gi
'
),
'
c
'
],
[
new
RegExp
(
'
[èéêë]
'
,
'
gi
'
),
'
e
'
],
[
new
RegExp
(
'
[ìíîï]
'
,
'
gi
'
),
'
i
'
],
[
new
RegExp
(
'
ñ
'
,
'
gi
'
),
'
n
'
],
[
new
RegExp
(
'
[òóôõö]
'
,
'
gi
'
),
'
o
'
],
[
new
RegExp
(
'
œ
'
,
'
gi
'
),
'
oe
'
],
[
new
RegExp
(
'
[ùúûü]
'
,
'
gi
'
),
'
u
'
],
[
new
RegExp
(
'
[ýÿ]
'
,
'
gi
'
),
'
y
'
]
];
module
(
'
Custom Key Queries
'
);
map
.
forEach
(
function
(
o
)
{
var
rep
=
function
(
match
)
{
if
(
match
.
toUpperCase
()
===
match
)
{
return
o
[
1
].
toUpperCase
();
}
return
o
[
1
];
};
s
=
s
.
replace
(
o
[
0
],
rep
);
});
return
s
;
};
var
noop
=
function
()
{
return
;
// use with RSVP.all
};
module
(
'
Custom Key Queries
'
);
test
(
'
Simple Key with read_from
'
,
function
()
{
var
docList
=
function
()
{
...
...
@@ -86,19 +116,14 @@
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
}
],
'
It should be possible to query with a case-insensitive alias key
'
);
],
'
It should be possible to query with a case-insensitive alias
'
+
'
key
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
var
dateCast
=
function
(
obj
)
{
return
new
jiodate
.
JIODate
(
obj
);
};
test
(
'
Simple Key with date casting
'
,
function
()
{
var
docList
=
function
()
{
return
[
...
...
@@ -109,48 +134,45 @@
{
'
identifier
'
:
'
c
'
,
'
date
'
:
'
2013-03-03
'
},
{
'
identifier
'
:
'
d
'
,
'
date
'
:
'
2013-04-04
'
}
];
},
promise
=
[];
var
sameDay
=
function
(
a
,
b
)
{
return
(
(
a
.
mom
.
year
()
===
b
.
mom
.
year
())
&&
(
a
.
mom
.
month
()
===
b
.
mom
.
month
())
&&
(
a
.
mom
.
date
()
===
b
.
mom
.
date
())
);
};
var
sameMonth
=
function
(
a
,
b
)
{
return
(
(
a
.
mom
.
year
()
===
b
.
mom
.
year
())
&&
(
a
.
mom
.
month
()
===
b
.
mom
.
month
())
);
};
var
sameYear
=
function
(
a
,
b
)
{
return
(
a
.
mom
.
year
()
===
b
.
mom
.
year
());
};
var
keys
=
{
day
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
sameDay
},
promise
=
[],
sameDay
=
function
(
a
,
b
)
{
return
(
(
a
.
mom
.
year
()
===
b
.
mom
.
year
())
&&
(
a
.
mom
.
month
()
===
b
.
mom
.
month
())
&&
(
a
.
mom
.
date
()
===
b
.
mom
.
date
())
);
},
month
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
sameMonth
sameMonth
=
function
(
a
,
b
)
{
return
(
(
a
.
mom
.
year
()
===
b
.
mom
.
year
())
&&
(
a
.
mom
.
month
()
===
b
.
mom
.
month
())
);
},
year
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
sameYear
sameYear
=
function
(
a
,
b
)
{
return
(
a
.
mom
.
year
()
===
b
.
mom
.
year
());
},
broken
:
{
read_from
:
'
date
'
,
cast_to
:
function
()
{
throw
new
Error
(
'
Broken!
'
);
}
}
};
keys
=
{
day
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
sameDay
},
month
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
sameMonth
},
year
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
sameYear
},
broken
:
{
read_from
:
'
date
'
,
cast_to
:
function
()
{
throw
new
Error
(
'
Broken!
'
);
}
}
};
stop
();
...
...
@@ -206,7 +228,8 @@
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
.
length
,
0
,
'
Constructors that throw exceptions should not break a query, but silently fail comparisons
'
);
'
Constructors that throw exceptions should not break a
'
+
'
query, but silently fail comparisons
'
);
})
);
...
...
@@ -482,15 +505,6 @@
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
var
translationEqualityMatcher
=
function
(
data
)
{
return
function
(
object_value
,
value
)
{
value
=
data
[
value
];
return
(
object_value
===
value
);
};
};
test
(
'
Simple Key with translation lookup
'
,
function
()
{
var
docList
=
function
()
{
return
[
...
...
@@ -518,7 +532,8 @@
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
It should be possible to look for a translated string with a custom match function
'
);
],
'
It should be possible to look for a translated string with a
'
+
'
custom match function
'
);
})
);
...
...
@@ -534,7 +549,8 @@
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
It should be possible to look for a translated string with operator =
'
);
],
'
It should be possible to look for a translated string with
'
+
'
operator =
'
);
})
);
...
...
@@ -548,42 +564,13 @@
// }).exec(doc_list);
// deepEqual(doc_list, [
// {'identifier': '2', 'state': 'closed'}
// ], 'It should be possible to look for a translated string with operator !=');
// ], 'It should be possible to look for a translated string with ' +
// 'operator !=');
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
// This method is provided as an example.
// A more robust solution to manage diacritics is recommended for production
// environments, with unicode normalization, like (untested):
// https://github.com/walling/unorm/
var
accentFold
=
function
(
s
)
{
var
map
=
[
[
new
RegExp
(
'
[àáâãäå]
'
,
'
gi
'
),
'
a
'
],
[
new
RegExp
(
'
æ
'
,
'
gi
'
),
'
ae
'
],
[
new
RegExp
(
'
ç
'
,
'
gi
'
),
'
c
'
],
[
new
RegExp
(
'
[èéêë]
'
,
'
gi
'
),
'
e
'
],
[
new
RegExp
(
'
[ìíîï]
'
,
'
gi
'
),
'
i
'
],
[
new
RegExp
(
'
ñ
'
,
'
gi
'
),
'
n
'
],
[
new
RegExp
(
'
[òóôõö]
'
,
'
gi
'
),
'
o
'
],
[
new
RegExp
(
'
œ
'
,
'
gi
'
),
'
oe
'
],
[
new
RegExp
(
'
[ùúûü]
'
,
'
gi
'
),
'
u
'
],
[
new
RegExp
(
'
[ýÿ]
'
,
'
gi
'
),
'
y
'
]
];
map
.
forEach
(
function
(
o
)
{
var
rep
=
function
(
match
)
{
if
(
match
.
toUpperCase
()
===
match
)
{
return
o
[
1
].
toUpperCase
();
}
return
o
[
1
];
};
s
=
s
.
replace
(
o
[
0
],
rep
);
});
return
s
;
};
test
(
'
Accent folding
'
,
function
()
{
equal
(
accentFold
(
'
àéîöùç
'
),
'
aeiouc
'
);
equal
(
accentFold
(
'
ÀÉÎÖÙÇ
'
),
'
AEIOUC
'
);
...
...
@@ -629,4 +616,4 @@
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
}));
}
(
jIO
,
jiodate
));
test/queries/tests.js
View file @
c8334d54
...
...
@@ -17,22 +17,16 @@
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, exports, require, module, jIO, window, test, ok,
deepEqual, stop, start, expect */
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
}
if
(
typeof
exports
===
'
object
'
)
{
return
module
(
require
(
'
jio
'
));
}
module
(
jIO
);
}([
'
jio
'
,
'
qunit
'
],
function
(
jIO
)
{
/*global jiodate*/
(
function
(
jIO
,
jiodate
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
deepEqual
=
QUnit
.
deepEqual
,
expect
=
QUnit
.
expect
,
ok
=
QUnit
.
ok
,
module
=
QUnit
.
module
;
module
(
'
Query
'
);
...
...
@@ -572,7 +566,7 @@
},
cast_lookup
:
{
dateType
:
function
(
str
)
{
return
window
.
jiodate
.
JIODate
(
new
Date
(
str
).
toISOString
());
return
jiodate
.
JIODate
(
new
Date
(
str
).
toISOString
());
}
}
};
...
...
@@ -655,4 +649,4 @@
}).
always
(
start
);
});
}));
}
(
jIO
,
jiodate
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment