mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-11 10:33:08 -06:00
Add Ref.maybeParse.
This commit is contained in:
@@ -82,6 +82,11 @@ export default class Ref {
|
||||
return new Ref(m[1]);
|
||||
}
|
||||
|
||||
static maybeParse(s: string): ?Ref {
|
||||
const m = s.match(pattern);
|
||||
return m ? new Ref(m[1]) : null;
|
||||
}
|
||||
|
||||
static fromDigest(digest: Uint8Array = new Uint8Array(sha1Size)) {
|
||||
return new Ref(sha1Prefix + uint8ArrayToHex(digest));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ suite('Ref', () => {
|
||||
assert.throws(() => {
|
||||
Ref.parse(s);
|
||||
});
|
||||
assert.equal(null, Ref.maybeParse(s));
|
||||
}
|
||||
|
||||
assertParseError('foo');
|
||||
@@ -27,8 +28,9 @@ suite('Ref', () => {
|
||||
// sha2 not supported
|
||||
assertParseError('sha2-0000000000000000000000000000000000000000');
|
||||
|
||||
const r = Ref.parse('sha1-0000000000000000000000000000000000000000');
|
||||
assert.isNotNull(r);
|
||||
const valid = 'sha1-0000000000000000000000000000000000000000';
|
||||
assert.isNotNull(Ref.parse(valid));
|
||||
assert.isNotNull(Ref.maybeParse(valid));
|
||||
});
|
||||
|
||||
test('equals', () => {
|
||||
|
||||
Reference in New Issue
Block a user