Last active
September 10, 2015 21:52
-
-
Save baer/eaf076767b026cf9257f to your computer and use it in GitHub Desktop.
Proposed Llama API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
import fs from "fs"; | |
import {docs} from "llama"; | |
import markdownReporter from "lamma-markdown"; | |
import Rectangle from "./rectangle.js"; | |
docs(Rectangle, { reporter: markdownReporter }) | |
.then((documentation) => { | |
return new Promise((resolve, reject) => { | |
fs.writeFile("/docs/Rectangle", documentation, function(err) { | |
if (err) { reject(err); } | |
resolve(documentation); | |
}); | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
import {params, returns} from "llama/decorators"; | |
import types from from "llama/types"; | |
@params([ | |
["length", types.number.natural()], | |
["width", types.number.natural()], | |
["id", types.string.guid(), ``` | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus tellus iaculis, | |
ullamcorper felis ullamcorper, feugiat orci. | |
```] | |
]) | |
export default class Rectangle { | |
constructor(length, width, id) { | |
this.length = length; | |
this.width = width; | |
this.id = id; | |
} | |
@params([ | |
["length", types.number.natural()], | |
["width", types.number.natural()] | |
]) | |
resetDimensions(length, width) { | |
this.length = length; | |
this.width = width; | |
} | |
@returns(types.number.natural()) | |
getArea() { | |
return this.length * this.width; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
import React from "react"; | |
import {propTypes, returns} from "llama/decorators"; | |
import types from "llama/types"; | |
@propTypes({ | |
"length": types.number.natural().required() | |
"width": types.number.natural().required() | |
"id": types.string.guid().description(``` | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus tellus iaculis, | |
ullamcorper felis ullamcorper, feugiat orci. | |
```) | |
}) | |
class Rectangle extends React.Component{ | |
constructor(length, width, id) { | |
this.length = length; | |
this.width = width; | |
this.id = id; | |
} | |
@return(types.number.natural()) | |
getArea() { | |
return this.length * this.width; | |
} | |
render() { | |
return (<span>I'm a Rectangle</span>) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
import {checkClass, checkFunction, generate} from "llama/test"; | |
import types from "llama/types"; | |
import Rectangle from "./rectangle.js"; | |
describe("Rectangle", () => { | |
describe("constructor", () => { | |
it("accepts correct input", () => { | |
// Validate 100 instances of Rectangle with random valid inputs | |
// Returns an A+ Promise where a rejection contains an array of Errors | |
return checkClass(Rectangle, 100); | |
}); | |
}); | |
describe("getArea", function() { | |
it("returns a natural number", () => { | |
// Instantiate 100 instances of Rectangle with random valid and invalid inputs | |
// Resolves to an A+ Promise containing instances | |
return generate.instance(Rectangle, 100) | |
.then((rectangles) => { | |
return instances.map((rectangle) => { | |
// Validate that a random valid input generates a valid output | |
return check(rectangle.getArea); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment