Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Some Tricks #1

Open
wants to merge 4 commits into from

2 participants

@timoxley

Hi, thought I'd show you some tricks you can do when developing your modules in the future.

#1. chop.chop? export the "primary" usecase as a function, and hang any additional functions off that. see chop.js
#2. Always have tests.

@mcandre
Owner

Yes, test driven development is ideal. I'd like to add more rigorous tests, such as generating text with random line endings and chopping/chomping that in the style of quickcheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2012
  1. @timoxley

    update package json

    timoxley authored
  2. @timoxley
  3. @timoxley

    and this is how you test

    timoxley authored
  4. @timoxley

    add git ignore

    timoxley authored
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 12 deletions.
  1. +1 −0  .gitignore
  2. +4 −3 chop.js
  3. +9 −9 package.json
  4. +23 −0 test.js
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
7 chop.js
@@ -1,10 +1,11 @@
-function chop(s) {
+var chop = function(s) {
return s.slice(0, s.length - 1);
}
+module.exports = exports = chop;
exports.chop = chop;
-function chomp(s) {
+var chomp = function(s) {
if (s.length < 1) {
return s;
}
@@ -19,4 +20,4 @@ function chomp(s) {
}
}
-exports.chomp = chomp;
+exports.chomp = chomp;
View
18 package.json
@@ -1,21 +1,21 @@
{
+ "author": "mcandre <andrew.pennebaker@gmail.com> (http://www.yellosoft.us/)",
"name": "chop",
"description": "A chop()/chomp() library for Node.js",
- "version": "0.0.1",
+ "version": "0.0.0",
+ "homepage": "https://github.com/mcandre/node-chop",
"repository": {
"type": "git",
"url": "git://github.com/mcandre/node-chop.git"
},
- "author": "Andrew Pennebaker <andrew.pennebaker@gmail.com> (http://www.yellosoft.us/)",
- "main": "chop",
- "directories": {
- "lib": "."
- },
+ "main": "index.js",
"scripts": {
+ "test": "./node_modules/.bin/mocha test.js"
},
+ "dependencies": {},
+ "devDependencies": {},
+ "optionalDependencies": {},
"engines": {
"node": "*"
- },
- "dependencies": {
}
-}
+}
View
23 test.js
@@ -0,0 +1,23 @@
+'use strict'
+
+var assert = require('assert')
+
+var chop = require("./chop")
+describe('chop', function() {
+ it('chops a single character', function() {
+ assert.equal(chop("Howdy!"), 'Howdy')
+ assert.equal(chop("Howdy!\n"), 'Howdy!')
+ assert.equal(chop("Howdy!\n\n"), 'Howdy!\n')
+ assert.equal(chop("Howdy!\r\n"), 'Howdy!\r')
+ })
+ it('is aliased to chop.chop', function() {
+ assert.strictEqual(chop.chop, chop)
+ })
+})
+describe('chomp', function() {
+ it('chomps off \r and \n characters', function() {
+ assert.equal(chop.chomp("Howdy!\n\n"), 'Howdy!')
+ assert.equal(chop.chomp("Howdy!\n\n"), 'Howdy!')
+ assert.equal(chop.chomp("Howdy!\r\n"), 'Howdy!')
+ })
+})
Something went wrong with that request. Please try again.