Converts WASM tests of Oxigraph lib to JavaScript tests

Much nicer and covers the same thing
pull/43/head
Tpt 4 years ago
parent c9d61ce3d5
commit 7e865fc30e
  1. 9
      .github/workflows/build.yml
  2. 6
      js/test/store.js
  3. 51
      lib/tests/wasm.rs

@ -31,15 +31,6 @@ jobs:
env:
RUST_BACKTRACE: 1
wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: rustup update
- run: cargo install wasm-pack
- run: wasm-pack test --node lib
- run: wasm-pack test --node js
js:
runs-on: ubuntu-latest
steps:

@ -71,6 +71,12 @@ describe('MemoryStore', function () {
assert.strictEqual(1, results.length)
assert(ex.equals(results[0].get('s')))
})
it('SELECT with NOW()', function () {
const store = new MemoryStore([dataFactory.triple(ex, ex, ex)])
const results = store.query('SELECT (YEAR(NOW()) AS ?y) WHERE {}')
assert.strictEqual(1, results.length)
})
})
describe('#load()', function () {

@ -1,51 +0,0 @@
#[cfg(target_arch = "wasm32")]
mod test {
use oxigraph::model::*;
use oxigraph::sparql::{QueryOptions, QueryResult};
use oxigraph::{MemoryStore, Result};
use std::str::FromStr;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]
fn simple() {
let store = MemoryStore::new();
// insertion
let ex = NamedNode::new("http://example.com").unwrap();
let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), None);
store.insert(quad.clone());
// quad filter
let results: Vec<Quad> = store.quads_for_pattern(None, None, None, None).collect();
assert_eq!(vec![quad], results);
// SPARQL query
let prepared_query = store
.prepare_query("SELECT ?s WHERE { ?s ?p ?o }", QueryOptions::default())
.unwrap();
let results = prepared_query.exec().unwrap();
if let QueryResult::Solutions(mut solutions) = results {
assert_eq!(
solutions.next().unwrap().unwrap().get("s"),
Some(&ex.into())
);
}
}
#[wasm_bindgen_test]
fn now() {
let store = MemoryStore::new();
let prepared_query = store
.prepare_query(
"SELECT (YEAR(NOW()) AS ?y) WHERE {}",
QueryOptions::default(),
)
.unwrap();
let results = prepared_query.exec().unwrap();
if let QueryResult::Solutions(mut solutions) = results {
if let Some(Term::Literal(l)) = solutions.next().unwrap().unwrap().get(0) {
let year = i64::from_str(l.value()).unwrap();
assert!(2020 <= year && year <= 2100);
}
}
}
}
Loading…
Cancel
Save