mirror of
https://github.com/github/semantic.git
synced 2024-11-24 17:04:47 +03:00
Add before/after fixtures.
This commit is contained in:
parent
c3c391f2cf
commit
19eb676e8e
53
prototype/doubt-difftool/Fixtures/after.js
vendored
Normal file
53
prototype/doubt-difftool/Fixtures/after.js
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
function diffFromJSON(json) {
|
||||
if (json.pure != null) { return new Diff({ pure: new Patch(json.pure) }); }
|
||||
if (json.roll != null) {
|
||||
return new Diff({
|
||||
roll: {
|
||||
extract: json.roll.extract,
|
||||
unwrap: new Syntax(json.roll.unwrap, function(x) { return diffFromJSON(x); })
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function Diff(object) {
|
||||
if (object.pure != null) { this.pure = object.pure; }
|
||||
if (object.roll != null) { this.roll = object.roll; }
|
||||
return this;
|
||||
}
|
||||
|
||||
// forall a b. Diff a -> (a -> b) -> Diff b
|
||||
Diff.prototype.map = function(transform) {
|
||||
if (this.pure != null) { return new Diff({ pure: transform(this.pure) }); }
|
||||
if (this.roll != null) {
|
||||
return new Diff({
|
||||
roll: {
|
||||
extract: this.roll.extract,
|
||||
unwrap: this.roll.unwrap.map(function(x) { return x.map(transform); })
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// forall a. Diff a -> (Syntax a -> a) -> a
|
||||
Diff.prototype.cata = function(transform) {
|
||||
if (this.pure != null) { return this.pure; }
|
||||
if (this.roll != null) {
|
||||
return transform(this.roll.unwrap.map(function(diff) {
|
||||
return diff.cata(transform);
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/// Diff -> String -> String -> DOM
|
||||
function diffToDOM(diff, which, source) {
|
||||
if (diff.pure != null) { return diff.pure; }
|
||||
|
||||
function getRange(diff) {
|
||||
if (diff.pure != null) { return diff.pure["data-range"]; }
|
||||
if (diff.roll != null) { return diff.roll.extract[which]; }
|
||||
}
|
||||
return rangeAndSyntaxToDOM(getRange(diff), diff.roll.unwrap, source, getRange, function(diff) {
|
||||
return diffToDOM(diff, which, source);
|
||||
})
|
||||
}
|
77
prototype/doubt-difftool/Fixtures/before.js
vendored
Normal file
77
prototype/doubt-difftool/Fixtures/before.js
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
function diffFromJSON(json) {
|
||||
if (json.pure != null) {
|
||||
return new Diff({
|
||||
pure: new Patch(json.pure)
|
||||
});
|
||||
}
|
||||
if (json.roll != null) {
|
||||
return new Diff({
|
||||
roll: {
|
||||
extract: json.roll.extract,
|
||||
unwrap: new Syntax(json.roll.unwrap, function(x) {
|
||||
return diffFromJSON(x);
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function Diff(object) {
|
||||
if (object.pure != null) {
|
||||
this.pure = object.pure;
|
||||
}
|
||||
if (object.roll != null) {
|
||||
this.roll = object.roll;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// forall a b. Diff a -> (a -> b) -> Diff b
|
||||
Diff.prototype.map = function(transform) {
|
||||
if (this.pure != null) {
|
||||
return new Diff({
|
||||
pure: transform(this.pure)
|
||||
});
|
||||
}
|
||||
if (this.roll != null) {
|
||||
return new Diff({
|
||||
roll: {
|
||||
extract: this.roll.extract,
|
||||
unwrap: this.roll.unwrap.map(function(x) {
|
||||
return x.map(transform);
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// forall a. Diff a -> (Syntax a -> a) -> a
|
||||
Diff.prototype.cata = function(transform) {
|
||||
if (this.pure != null) {
|
||||
return this.pure;
|
||||
}
|
||||
if (this.roll != null) {
|
||||
return transform(this.roll.unwrap.map(function(diff) {
|
||||
return diff.cata(transform);
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/// Diff -> String -> String -> DOM
|
||||
function diffToDOM(diff, which, source) {
|
||||
if (diff.pure != null) {
|
||||
return diff.pure;
|
||||
}
|
||||
|
||||
function getRange(diff) {
|
||||
if (diff.pure != null) {
|
||||
return diff.pure["data-range"];
|
||||
}
|
||||
if (diff.roll != null) {
|
||||
return diff.roll.extract[which];
|
||||
}
|
||||
}
|
||||
return rangeAndSyntaxToDOM(getRange(diff), diff.roll.unwrap, source, getRange, function(diff) {
|
||||
return diffToDOM(diff, which, source);
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user