Comparing version 0.0.10 to 0.0.11
@@ -14,2 +14,3 @@ var xl = require('./lib/libxl'); | ||
format = book.addFormat(); | ||
format.setFont(book.addFont().setSize(20)); | ||
sheet | ||
@@ -16,0 +17,0 @@ .writeStr(row, 0, 'green', format); |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "libxl bindings for node", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
@@ -29,4 +29,8 @@ # What it is | ||
(loading and async writing are not implemented atm). | ||
and read back via | ||
xlsBook.loadSync('file.xls'); | ||
(async operations are not implemented atm). | ||
The API closely follows the | ||
@@ -50,6 +54,8 @@ [libxl documentation](http://www.libxl.com/documentation.html). | ||
API coverage is a work in progress; see demo.js, | ||
jasmine specs and the class initializers | ||
(Book::Initialize, Sheet::Initialize, Format::Initialize) | ||
to find out what is currently supported :). | ||
API coverage is a work in progress. At the moment, the Font class is fully | ||
implemented, and the other three classes (Book, Sheet and Format) are covered | ||
sufficiently to support reading and writing documents. Please see | ||
the jasmine specs and the class initializers | ||
(Book::Initialize, Sheet::Initialize, Format::Initialize, Font::Initialize) | ||
for a more detailed overview of what is currently supported :). | ||
@@ -80,2 +86,4 @@ ## Unlocking the API | ||
* Martin Schröder for adding Mac support. | ||
* Parts if this package were developed during slacktime provided by the awesome folks at | ||
[Mayflower GmbH](http://www.mayflower.de) | ||
* Alexander Makarenko wrote | ||
@@ -82,0 +90,0 @@ [node-excel-libxl](https://github.com/7eggs/node-excel-libxl) |
@@ -1,3 +0,136 @@ | ||
var xl = require('../lib/libxl'); | ||
var xl = require('../lib/libxl'), | ||
util = require('util'), | ||
testUtils = require('./testUtils'); | ||
function shouldThrow(fun, scope) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
expect(function() {fun.apply(scope, args);}).toThrow(); | ||
} | ||
testUtils.initFilesystem(); | ||
describe('The font class', function() { | ||
var book = new xl.Book(xl.BOOK_TYPE_XLS), | ||
font = book.addFont(); | ||
it('The font constructor can not be called directly', function() { | ||
expect(function() {new font.constructor();}).toThrow(); | ||
}); | ||
it('font.size reads font size', function() { | ||
shouldThrow(font.size, book); | ||
font.setSize(10); | ||
expect(font.size()).toBe(10); | ||
font.setSize(20); | ||
expect(font.size()).toBe(20); | ||
}); | ||
it('font.setSize sets font size', function() { | ||
shouldThrow(font.setSize, font, ''); | ||
shouldThrow(font.setSize, {}, 10); | ||
expect(font.setSize(10)).toBe(font); | ||
}); | ||
it('font.italic checks wether a font is italic', function() { | ||
shouldThrow(font.italic, book); | ||
font.setItalic(false); | ||
expect(font.italic()).toBe(false); | ||
font.setItalic(true); | ||
expect(font.italic()).toBe(true); | ||
}); | ||
it('font.setItalic toggles a font italic', function() { | ||
shouldThrow(font.setItalic, font, 10); | ||
shouldThrow(font.setItalic, book, true); | ||
expect(font.setItalic(true)).toBe(font); | ||
}); | ||
it('font.strikeOut checks wether a font is striked out', function() { | ||
shouldThrow(font.strikeOut, book); | ||
font.setStrikeOut(false); | ||
expect(font.strikeOut()).toBe(false); | ||
font.setStrikeOut(true); | ||
expect(font.strikeOut()).toBe(true); | ||
}); | ||
it('font.setStrikeOut toggles a font striked out', function() { | ||
shouldThrow(font.setStrikeOut, font, 10); | ||
shouldThrow(font.setStrikeOut, book, true); | ||
expect(font.setStrikeOut(true)).toBe(font); | ||
}); | ||
it('font.color gets font color', function() { | ||
shouldThrow(font.color, book); | ||
font.setColor(xl.COLOR_BLACK); | ||
expect(font.color()).toBe(xl.COLOR_BLACK); | ||
font.setColor(xl.COLOR_WHITE); | ||
expect(font.color()).toBe(xl.COLOR_WHITE); | ||
}); | ||
it('font.setColor sets font color', function() { | ||
shouldThrow(font.setColor, font, true); | ||
shouldThrow(font.setColor, book, xl.COLOR_BLACK); | ||
expect(font.setColor(xl.COLOR_BLACK)).toBe(font); | ||
}); | ||
it('font.bold checks whether a font is bold', function() { | ||
shouldThrow(font.bold, book); | ||
font.setBold(false); | ||
expect(font.bold()).toBe(false); | ||
font.setBold(true); | ||
expect(font.bold()).toBe(true); | ||
}); | ||
it('font.setBold toggles a font bold', function() { | ||
shouldThrow(font.setBold, font, 10); | ||
shouldThrow(font.setBold, book, true); | ||
expect(font.setBold(true)).toBe(font); | ||
}); | ||
it('font.script gets a fonts script style', function() { | ||
shouldThrow(font.script, book); | ||
font.setScript(xl.SCRIPT_NORMAL); | ||
expect(font.script()).toBe(xl.SCRIPT_NORMAL); | ||
font.setScript(xl.SCRIPT_SUPER); | ||
expect(font.script()).toBe(xl.SCRIPT_SUPER); | ||
}); | ||
it('font.setScript sets a fonts script style', function() { | ||
shouldThrow(font.setScript, font, ''); | ||
shouldThrow(font.setScript, book, xl.SCRIPT_NORMAL); | ||
expect(font.setScript(xl.SCRIPT_NORMAL)).toBe(font); | ||
}); | ||
it('font.underline gets a fonts underline mode', function() { | ||
shouldThrow(font.underline, book); | ||
font.setUnderline(xl.UNDERLINE_NONE); | ||
expect(font.underline()).toBe(xl.UNDERLINE_NONE); | ||
font.setUnderline(xl.UNDERLINE_SINGLE); | ||
expect(font.underline()).toBe(xl.UNDERLINE_SINGLE); | ||
}); | ||
it('font.setUnderline sets a fonts underline mode', function() { | ||
shouldThrow(font.setUnderline, font, true); | ||
shouldThrow(font.setUnderline, book, xl.UNDERLINE_NONE); | ||
expect(font.setUnderline(xl.UNDERLINE_NONE)).toBe(font); | ||
}); | ||
it('font.name gets the font name', function() { | ||
shouldThrow(font.name, book); | ||
font.setName('arial'); | ||
expect(font.name()).toBe('arial'); | ||
font.setName('times'); | ||
expect(font.name()).toBe('times'); | ||
}); | ||
it('font.setName sets the font name', function() { | ||
shouldThrow(font.setName, font, 10); | ||
shouldThrow(font.setName, book, 'arial'); | ||
expect(font.setName('arial')).toBe(font); | ||
}); | ||
}); | ||
describe('The sheet class', function() { | ||
@@ -33,3 +166,3 @@ | ||
expect(function() {sheet.isFormula();}).toThrow(); | ||
expect(function() {sheet.isFormula.call({}, row, 0)}).toThrow(); | ||
expect(function() {sheet.isFormula.call({}, row, 0);}).toThrow(); | ||
@@ -260,3 +393,3 @@ expect(sheet.isFormula(row, 0)).toBe(false); | ||
expect(function() {sheet.setRowHidden();}).toThrow(); | ||
expect(function() {sheet.setRowHidden.call({}, row, true)}).toThrow(); | ||
expect(function() {sheet.setRowHidden.call({}, row, true);}).toThrow(); | ||
@@ -278,3 +411,3 @@ expect(sheet.setRowHidden(row, true)).toBe(sheet); | ||
expect(function() {sheet.setColHidden();}).toThrow(); | ||
expect(function() {sheet.setColHidden.call({}, 0, true)}).toThrow(); | ||
expect(function() {sheet.setColHidden.call({}, 0, true);}).toThrow(); | ||
@@ -285,4 +418,133 @@ expect(sheet.setColHidden(0, true)).toBe(sheet); | ||
expect(sheet.colHidden(0)).toBe(false); | ||
}) | ||
}); | ||
}); | ||
describe('The book class', function() { | ||
var book; | ||
beforeEach(function() { | ||
book = new xl.Book(xl.BOOK_TYPE_XLS); | ||
}); | ||
it('Books are created via the book constructor', function() { | ||
expect(function() {var book = new xl.Book();}).toThrow(); | ||
expect(function() {var book = new xl.Book(200);}).toThrow(); | ||
expect(function() {var book = new xl.Book('a');}).toThrow(); | ||
var bookXls = new xl.Book(xl.BOOK_TYPE_XLS), | ||
bookXlsx = new xl.Book(xl.BOOK_TYPE_XLSX); | ||
}); | ||
it('book.writeSync writes a book in sync mode', function() { | ||
var sheet = book.addSheet('foo'); | ||
sheet.writeStr(1, 0, 'bar'); | ||
var file = testUtils.getWriteTestFile(); | ||
shouldThrow(book.writeSync, book, 10); | ||
shouldThrow(book.writeSync, {}, file); | ||
expect(book.writeSync(file)).toBe(book); | ||
}); | ||
it('book.loadSync loads a book in sync mode', function() { | ||
var file = testUtils.getWriteTestFile(); | ||
shouldThrow(book.loadSync, book, 10); | ||
shouldThrow(book.loadSync, {}, file); | ||
expect(book.loadSync(file)).toBe(book); | ||
var sheet = book.getSheet(0); | ||
expect(sheet.readStr(1, 0)).toBe('bar'); | ||
}); | ||
it('book.addSheet adds a sheet to a book', function() { | ||
shouldThrow(book.addSheet, book, 10); | ||
shouldThrow(book.addSheet, {}, 'foo'); | ||
book.addSheet('baz', 10); | ||
var sheet1 = book.addSheet('foo'); | ||
sheet1.writeStr(1, 0, 'aaa'); | ||
var sheet2 = book.addSheet('bar', sheet1); | ||
expect(sheet2.readStr(1, 0)).toBe('aaa'); | ||
}); | ||
it('book.insertSheet inserts a sheet at a given position', function() { | ||
var sheet1 = book.addSheet('foo'); | ||
sheet1.writeStr(1, 0, 'bbb'); | ||
shouldThrow(book.insertSheet, book, 'a', 'bar'); | ||
shouldThrow(book.insertSheet, book, 2, 'bar'); | ||
shouldThrow(book.insertSheet, {}, 0, 'bar'); | ||
book.insertSheet(0, 'bar'); | ||
expect(book.sheetCount()).toBe(2); | ||
var sheet2 = book.insertSheet(0, 'baz', sheet1); | ||
expect(sheet2.readStr(1, 0)).toBe('bbb'); | ||
}); | ||
it('book.getSheet retrieves a sheet at a given index', function() { | ||
var sheet = book.addSheet('foo'); | ||
sheet.writeStr(1, 0, 'bar'); | ||
shouldThrow(book.getSheet, book, 'a'); | ||
shouldThrow(book.getSheet, book, 1); | ||
shouldThrow(book.getSheet, {}, 0); | ||
var sheet2 = book.getSheet(0); | ||
expect(sheet2.readStr(1, 0)).toBe('bar'); | ||
}); | ||
it('book.sheetType determines sheet type', function() { | ||
var sheet = book.addSheet('foo'); | ||
shouldThrow(book.sheetType, book, 'a'); | ||
shouldThrow(book.sheetType, {}, 0); | ||
expect(book.sheetType(0)).toBe(xl.SHEETTYPE_SHEET); | ||
expect(book.sheetType(1)).toBe(xl.SHEETTYPE_UNKNOWN); | ||
}); | ||
it('book.delSheet removes a sheet', function() { | ||
book.addSheet('foo'); | ||
book.addSheet('bar'); | ||
shouldThrow(book.delSheet, book, 'a'); | ||
shouldThrow(book.delSheet, book, 3); | ||
shouldThrow(book.delSheet, {}, 0); | ||
expect(book.delSheet(0)).toBe(book); | ||
expect(book.sheetCount()).toBe(1); | ||
}); | ||
it('book.sheetCount counts the number of sheets in a book', function() { | ||
shouldThrow(book.sheetCount, {}); | ||
expect(book.sheetCount()).toBe(0); | ||
book.addSheet('foo'); | ||
expect(book.sheetCount()).toBe(1); | ||
}); | ||
it('book.addFormat adds a format', function() { | ||
shouldThrow(book.addFormat, {}); | ||
book.addFormat('a'); | ||
book.addFormat(); | ||
// TODO add a check for format inheritance once format has been | ||
// completed | ||
}); | ||
it('book.addFont adds a font', function() { | ||
shouldThrow(book.addFont, {}); | ||
book.addFont(10); | ||
var font1 = book.addFont(); | ||
font1.setName('times'); | ||
expect(book.addFont(font1).name()).toBe('times'); | ||
}); | ||
it('book.addCusomtNumFormat adds a custom number format', function() { | ||
shouldThrow(book.addCusomtNumFormat, book, 10); | ||
shouldThrow(book.addCusomtNumFormat, {}, '000'); | ||
book.addCustomNumFormat('000'); | ||
}); | ||
it('book.customNumFormat retrieves a custom number format', function() { | ||
var format = book.addCustomNumFormat('000'); | ||
shouldThrow(book.customNumFormat, book, 'a'); | ||
shouldThrow(book.customNumFormat, {}, format); | ||
expect(book.customNumFormat(format)).toBe('000'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
795112
34
590
90
4