Skip to content

Commit

Permalink
statementByLabel utility
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 5, 2015
1 parent 738c0f5 commit 41ccfdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/smm/scoper.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ class MMScoper {
}
}

MMOMDatabase.prototype.statementByLabel = function(label) {
let sym = this.scoper.lookup(label);
return sym ? sym.labelled : null;
};

var HIGHSEG = MMScoper.HIGHSEG = -1 >>> 1;
// MM files larger than 2GB are likely to cause no end of problems...

Expand Down
16 changes: 12 additions & 4 deletions test/scoper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var MMOM = require('../lib/smm/mmom');
var expect = require('chai').expect;
require('../lib/smm/scoper');
import { describeDB } from './lib/util';
var db, errlist;
function src(x) {
before(function () {
Expand Down Expand Up @@ -348,9 +349,16 @@ var cases = [
},
];

cases.forEach(function (cc) {
describe(`${cc.name}:`, function () {
src(cc.src);
errs(cc.errs);
describe('scoper i/o:', () => {
cases.forEach(function (cc) {
describe(`${cc.name}:`, function () {
src(cc.src);
errs(cc.errs);
});
});
});

describeDB('scoper utilities', '$c foo $. bar $a foo $.', dbt => {
it('statementByLabel (fail)', () => expect(dbt().statementByLabel('bar2')).to.equal(null));
it('statementByLabel (success)', () => expect(dbt().statementByLabel('bar').math).to.eql(['foo']));
});

0 comments on commit 41ccfdf

Please sign in to comment.