Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achieve better test coverage for Triples and Transform functions #73

Merged
merged 4 commits into from Jan 16, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Remove unrechable code from toClass.

We check for classes.size right after adding wellKnownTypes to that set.
It will never be 0.

The assertion in BuildClasses will never be true, since IsClass is the
same condition as what causes this content to be added. Instead of
bespoke exceptions, we use node's assertion to make sure that this won't
happen.

More philosophically, we should use this type of assertion whenever --
within the bounds of an exported function -- regardless of its inputs,
a certain condition is impossible.

Instead let's just make sure explicit exceptions are used for things that
can go wrong in actuality.
  • Loading branch information
Eyas committed Jan 16, 2020
commit 11c9f64397e0ddbe29f09ac1b8945fd72d7ad213
@@ -14,12 +14,16 @@
* limitations under the License.
*/

import {ok} from 'assert';

import {Log} from '../logging';
import {ObjectPredicate, Topic, TypedTopic} from '../triples/triple';
import {UrlNode} from '../triples/types';
import {IsClass} from '../triples/wellKnown';
import {BooleanEnum, Builtin, Class, ClassMap, DataTypeUnion} from '../ts/class';

const assert: <T>(item: T|undefined) => asserts item is T = ok;

function toClass(cls: Class, topic: Topic, map: ClassMap): Class {
const rest: ObjectPredicate[] = [];
for (const value of topic.values) {
@@ -87,10 +91,6 @@ function ForwardDeclareClasses(topics: ReadonlyArray<TypedTopic>): ClassMap {
topic.Subject.toString(), new Class(topic.Subject, allowString));
}

if (classes.size === 0) {
throw new Error('Expected Class topics to exist.');
}

return classes;
}

@@ -99,10 +99,7 @@ function BuildClasses(topics: ReadonlyArray<TypedTopic>, classes: ClassMap) {
if (!IsClass(topic)) continue;

const cls = classes.get(topic.Subject.toString());
if (!cls) {
throw new Error(`Class ${
topic.Subject.toString()} should have been forward declared.`);
}
assert(cls);
toClass(cls, topic, classes);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.