Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added truncate/truncateHTML tests from Geddy helper tests, because th…

…e implementation of those are in lib/string.js and not in Geddy itself anymore.

Also made a couple jsdoc changes.
  • Loading branch information...
commit d9b47dab3994332d34d9765f230a3da8f5ad79e8 1 parent 6dfd582
Larz Conwell larzconwell authored
12 lib/date.js
@@ -202,7 +202,7 @@ date = new (function () {
202 202 @public
203 203 @function
204 204 @return {String} The `dt` formated with the given `format`
205   - @description Formats the given date with the strftime format
  205 + @description Formats the given date with the strftime formated
206 206 @param {Date} dt the date object to format
207 207 @param {String} format the format to convert the date to
208 208 */
@@ -242,7 +242,7 @@ date = new (function () {
242 242 @function
243 243 @return {String} The century for the given date
244 244 @description Find the century for the given `year`
245   - @param {String} year The year to find the century for
  245 + @param {Number} year The year to find the century for
246 246 */
247 247 this.calcCentury = function (year) {
248 248 if(!year) {
@@ -335,7 +335,7 @@ date = new (function () {
335 335 @return {String} Return a 24 hour version of the given time
336 336 @description Convert a 12-hour formatted hour with meridian flag to 24-hour format
337 337 @param {String} hour The hour to convert
338   - @param {Boolean} If hour is PM then this should be true
  338 + @param {Boolean} pm hour is PM then this should be true
339 339 */
340 340 this.hrStd2Mil = function (hour, pm) {
341 341 var h = typeof hour == 'number' ? hour : parseInt(hour);
@@ -378,7 +378,7 @@ date = new (function () {
378 378 @function
379 379 @return {Date} Incremented date
380 380 @description Add to a Date in intervals of different size, from
381   - milliseconds to years
  381 + milliseconds to years
382 382 @param {Date} dt Date (or timestamp Number), date to increment
383 383 @param {String} interv a constant representing the interval,
384 384 e.g. YEAR, MONTH, DAY. See this.dateParts
@@ -484,7 +484,7 @@ date = new (function () {
484 484 @return {Number} number of (interv) units apart that
485 485 the two dates are
486 486 @description Get the difference in a specific unit of time (e.g., number
487   - of months, weeks, days, etc.) between two dates.
  487 + of months, weeks, days, etc.) between two dates.
488 488 @param {Date} date1 First date to check
489 489 @param {Date} date2 Date to compate `date1` with
490 490 @param {String} interv a constant representing the interval,
@@ -649,7 +649,7 @@ date = new (function () {
649 649 @function
650 650 @return {Date} a JavaScript Date object
651 651 @description Convert various sorts of strings to JavaScript
652   - Date objects
  652 + Date objects
653 653 @param {String} val The string to convert to a Date
654 654 */
655 655 this.parse = function (val) {
2  lib/event_buffer.js
@@ -60,7 +60,7 @@ EventBuffer.prototype = new (function () {
60 60 @public
61 61 @function
62 62 @description Emit an event by name and arguments or add it to the buffer if
63   - no outlet is set
  63 + no outlet is set
64 64 @param {String} name The name to use for the event
65 65 @param {Array} args An array of arguments to emit
66 66 */
1  lib/request.js
@@ -49,6 +49,7 @@ var formatters = {
49 49 @param {Object} [opts.headers] Headers to send on requests
50 50 @param {String} [opts.data] Data to send on POST and PUT requests
51 51 @param {String} [opts.dataType] The type of data to send
  52 + @param {Function} callback the function to call after, args are `error, data`
52 53 */
53 54 var request = function (opts, callback) {
54 55 var client
6 lib/string.js
@@ -108,7 +108,7 @@ string = new (function () {
108 108 @function
109 109 @return {String} A string of escaped characters
110 110 @description Escapes regex control-characters in strings
111   - used to build regexes dynamically
  111 + used to build regexes dynamically
112 112 @param {String} string The string of chars to escape
113 113 */
114 114 this.escapeRegExpChars = (function () {
@@ -219,8 +219,8 @@ string = new (function () {
219 219 @public
220 220 @function
221 221 @description Returns a new String with the last character removed. If the
222   - string ends with \r\n, both characters are removed. Applying chop to an
223   - empty string returns an empty string.
  222 + string ends with \r\n, both characters are removed. Applying chop to an
  223 + empty string returns an empty string.
224 224 @param {String} string to return with the last character removed.
225 225 */
226 226 this.chop = function (string) {
2  lib/uri.js
@@ -37,7 +37,7 @@ uri = new (function () {
37 37 @public
38 38 @function
39 39 @return {String} Returns the file extension for a given path
40   - @description Gets the file extension fir a path and returns it
  40 + @description Gets the file extension for a path and returns it
41 41 @param {String} path The path to get the extension for
42 42 */
43 43 this.getFileExtension = function (path) {
41 test/string.js
@@ -238,8 +238,45 @@ tests = {
238 238 assert.equal(expected, data);
239 239 }
240 240
241   - // We could test truncate and truncateHTML here, but helper tests already
242   - // include tests for them
  241 +, 'test single tags in truncateHTML': function () {
  242 + var str = string.truncateHTML('<p>Once upon a time in a world</p>', { length: 10 });
  243 + assert.equal(str, '<p>Once up...</p>');
  244 + }
  245 +
  246 +, 'test multiple tags in truncateHTML': function () {
  247 + var str = string.truncateHTML('<p>Once upon a time <small>in a world</small></p>', { length: 10 });
  248 + assert.equal(str, '<p>Once up...<small>in a wo...</small></p>');
  249 + }
  250 +
  251 +, 'test multiple tags but only truncate once in truncateHTML': function () {
  252 + var str = string.truncateHTML('<p>Once upon a time <small>in a world</small></p>', { length: 10, once: true });
  253 + assert.equal(str, '<p>Once up...<small>in a world</small></p>');
  254 + }
  255 +
  256 +, 'test standard truncate': function () {
  257 + var str = string.truncate('Once upon a time in a world', { length: 10 });
  258 + assert.equal(str, 'Once up...');
  259 + }
  260 +
  261 +, 'test custom omission in truncate': function () {
  262 + var str = string.truncate('Once upon a time in a world', { length: 10, omission: '///' });
  263 + assert.equal(str, 'Once up///');
  264 + }
  265 +
  266 +, 'test regex seperator in truncate': function () {
  267 + var str = string.truncate('Once upon a time in a world', { length: 15, seperator: /\s/ });
  268 + assert.equal(str, 'Once upon a...');
  269 + }
  270 +
  271 +, 'test string seperator in truncate': function () {
  272 + var str = string.truncate('Once upon a time in a world', { length: 15, seperator: ' ' });
  273 + assert.equal(str, 'Once upon a...');
  274 + }
  275 +
  276 +, 'test unsafe html in truncate': function () {
  277 + var str = string.truncate('<p>Once upon a time in a world</p>', { length: 20 });
  278 + assert.equal(str, '<p>Once upon a ti...');
  279 + }
243 280
244 281 , 'test nl2br for string': function () {
245 282 var data = string.nl2br("geddy\n")

0 comments on commit d9b47da

Please sign in to comment.
Something went wrong with that request. Please try again.