From c2dbdc0ff3dd3e78b94af3709c598cb2eeb46b23 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Mon, 6 Mar 2017 13:42:11 -0500 Subject: [PATCH 1/2] language: re-work encoding property --- packages/language/src/document.js | 60 +++++++++++++++++++++++++------ packages/language/src/index.js | 26 +++++++------- 2 files changed, 62 insertions(+), 24 deletions(-) diff --git a/packages/language/src/document.js b/packages/language/src/document.js index 21a4e496fe1..83391d201a5 100644 --- a/packages/language/src/document.js +++ b/packages/language/src/document.js @@ -44,8 +44,6 @@ var prop = require('propprop'); * object to specify the encoding and/or language of the document, use this * property to pass the inline content of the document or a Storage File * object. - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). * @param {string} options.language - The language of the text. * @return {module:language/document} * @@ -69,13 +67,10 @@ function Document(language, config) { var content = config.content || config; this.api = language.api; + this.encodingType = 'UTF16'; this.document = {}; - if (config.encoding) { - this.encodingType = config.encoding.toUpperCase().replace(/[ -]/g, ''); - } - if (config.language) { this.document.language = config.language; } @@ -98,6 +93,10 @@ function Document(language, config) { }); } else { this.document.content = content; + + if (Buffer.isBuffer(content)) { + this.encodingType = 'UTF8'; + } } } @@ -232,6 +231,9 @@ Document.PART_OF_SPEECH = { * * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/annotateText#features). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.entities - Detect the entities from this document. * By default, all features (`entities`, `sentiment`, and `syntax`) are * enabled. By overriding any of these values, all defaults are switched to @@ -547,7 +549,7 @@ Document.prototype.annotate = function(options, callback) { this.api.Language.annotateText({ document: this.document, features: features, - encodingType: this.encodingType + encodingType: this.detectEncodingType_(options) }, function(err, resp) { if (err) { callback(err, null, resp); @@ -587,6 +589,9 @@ Document.prototype.annotate = function(options, callback) { * * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeEntities#request-body). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.verbose - Enable verbose mode for more detailed * results. Default: `false` * @param {function} callback - The callback function. @@ -699,7 +704,7 @@ Document.prototype.detectEntities = function(options, callback) { this.api.Language.analyzeEntities({ document: this.document, - encodingType: this.encodingType + encodingType: this.detectEncodingType_(options) }, function(err, resp) { if (err) { callback(err, null, resp); @@ -720,6 +725,9 @@ Document.prototype.detectEntities = function(options, callback) { * * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSentiment#request-body). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.verbose - Enable verbose mode for more detailed * results. Default: `false` * @param {function} callback - The callback function. @@ -784,7 +792,7 @@ Document.prototype.detectSentiment = function(options, callback) { this.api.Language.analyzeSentiment({ document: this.document, - encodingType: this.encodingType + encodingType: this.detectEncodingType_(options) }, function(err, resp) { if (err) { callback(err, null, resp); @@ -812,6 +820,9 @@ Document.prototype.detectSentiment = function(options, callback) { * * @param {object=} options - Configuration object. See * [documents.annotateSyntax](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSyntax#request-body). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.verbose - Enable verbose mode for more detailed * results. Default: `false` * @param {function} callback - The callback function. @@ -952,7 +963,7 @@ Document.prototype.detectSyntax = function(options, callback) { this.api.Language.analyzeSyntax({ document: this.document, - encodingType: this.encodingType + encodingType: this.detectEncodingType_(options) }, function(err, resp) { if (err) { callback(err, null, resp); @@ -1126,6 +1137,35 @@ Document.sortByProperty_ = function(propertyName) { }; }; +/** + * Check if the user provided an encodingType, and map it to its API value. + * + * @param {object} options - Configuration object. + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) + * @return {string} - The encodingType, as understood by the API. + */ +Document.prototype.detectEncodingType_ = function(options) { + var encoding = this.encodingType || options.encoding || options.encodingType; + + if (!encoding) { + return; + } + + encoding = encoding.toUpperCase().replace(/[ -]/g, ''); + + if (encoding === 'BUFFER') { + encoding = 'UTF8'; + } + + if (encoding === 'STRING') { + encoding = 'UTF16'; + } + + return encoding; +}; + /*! Developer Documentation * * All async methods (except for streams) will return a Promise in the event diff --git a/packages/language/src/index.js b/packages/language/src/index.js index 02c8ec7d27f..252ea84377c 100644 --- a/packages/language/src/index.js +++ b/packages/language/src/index.js @@ -81,8 +81,9 @@ function Language(options) { * File object. * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/annotateText#request-body). - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. * @param {boolean} options.verbose - Enable verbose mode for more detailed @@ -173,8 +174,9 @@ Language.prototype.annotate = function(content, options, callback) { * File object. * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeEntities#request-body). - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. * @param {boolean} options.verbose - Enable verbose mode for more detailed @@ -264,8 +266,9 @@ Language.prototype.detectEntities = function(content, options, callback) { * File object. * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSentiment#request-body). - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. * @param {boolean} options.verbose - Enable verbose mode for more detailed @@ -346,8 +349,9 @@ Language.prototype.detectSentiment = function(content, options, callback) { * File object. * @param {object=} options - Configuration object. See * [documents.analyzeSyntax](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSyntax#request-body). - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). + * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also + * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. * @param {boolean} options.verbose - Enable verbose mode for more detailed @@ -436,8 +440,6 @@ Language.prototype.detectSyntax = function(content, options, callback) { * object to specify the encoding and/or language of the document, use this * property to pass the inline content of the document or a Storage File * object. - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). * @param {string} options.language - The language of the text. * @return {module:language/document} * @@ -481,8 +483,6 @@ Language.prototype.document = function(config) { * @param {string|module:storage/file} content - Inline HTML content or a * Storage File object. * @param {object=} options - Configuration object. - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). * @param {string} options.language - The language of the text. * @return {module:language/document} * @@ -531,8 +531,6 @@ Language.prototype.html = function(content, options) { * @param {string|module:storage/file} content - Inline text content or a * Storage File object. * @param {object=} options - Configuration object. - * @param {string} options.encoding - `UTF8`, `UTF16`, or `UTF32`. See - * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType). * @param {string} options.language - The language of the text. * @return {module:language/document} * From 94cb07a1ba8781dd3e46b9ad7339fcaa1da3624c Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Wed, 8 Mar 2017 14:17:02 -0500 Subject: [PATCH 2/2] update docs & add tests --- packages/language/src/document.js | 19 ++-- packages/language/src/index.js | 12 ++- packages/language/test/document.js | 144 +++++++++++++++++++++++++---- 3 files changed, 144 insertions(+), 31 deletions(-) diff --git a/packages/language/src/document.js b/packages/language/src/document.js index 83391d201a5..93caf8a4ef7 100644 --- a/packages/language/src/document.js +++ b/packages/language/src/document.js @@ -67,7 +67,7 @@ function Document(language, config) { var content = config.content || config; this.api = language.api; - this.encodingType = 'UTF16'; + this.encodingType = this.detectEncodingType_(config); this.document = {}; @@ -232,7 +232,8 @@ Document.PART_OF_SPEECH = { * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/annotateText#features). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.entities - Detect the entities from this document. * By default, all features (`entities`, `sentiment`, and `syntax`) are @@ -590,7 +591,8 @@ Document.prototype.annotate = function(options, callback) { * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeEntities#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.verbose - Enable verbose mode for more detailed * results. Default: `false` @@ -726,7 +728,8 @@ Document.prototype.detectEntities = function(options, callback) { * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSentiment#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.verbose - Enable verbose mode for more detailed * results. Default: `false` @@ -821,7 +824,8 @@ Document.prototype.detectSentiment = function(options, callback) { * @param {object=} options - Configuration object. See * [documents.annotateSyntax](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSyntax#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {boolean} options.verbose - Enable verbose mode for more detailed * results. Default: `false` @@ -1142,12 +1146,13 @@ Document.sortByProperty_ = function(propertyName) { * * @param {object} options - Configuration object. * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @return {string} - The encodingType, as understood by the API. */ Document.prototype.detectEncodingType_ = function(options) { - var encoding = this.encodingType || options.encoding || options.encodingType; + var encoding = options.encoding || options.encodingType || this.encodingType; if (!encoding) { return; diff --git a/packages/language/src/index.js b/packages/language/src/index.js index 252ea84377c..092cbc1d613 100644 --- a/packages/language/src/index.js +++ b/packages/language/src/index.js @@ -82,7 +82,8 @@ function Language(options) { * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/annotateText#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. @@ -175,7 +176,8 @@ Language.prototype.annotate = function(content, options, callback) { * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeEntities#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. @@ -267,7 +269,8 @@ Language.prototype.detectEntities = function(content, options, callback) { * @param {object=} options - Configuration object. See * [documents.annotateText](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSentiment#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. @@ -350,7 +353,8 @@ Language.prototype.detectSentiment = function(content, options, callback) { * @param {object=} options - Configuration object. See * [documents.analyzeSyntax](https://cloud.google.com/natural-language/reference/rest/v1/documents/analyzeSyntax#request-body). * @param {string} options.encoding - `UTF8` (also, `buffer`), `UTF16` (also - * `string`), or `UTF32`. (Alias for `options.encodingType`). See + * `string`), or `UTF32`. (Alias for `options.encodingType`). Default: + * 'UTF8' if a Buffer, otherwise 'UTF16'. See * [`EncodingType`](https://cloud.google.com/natural-language/reference/rest/v1/EncodingType) * @param {string} options.language - The language of the text. * @param {string} options.type - The type of document, either `html` or `text`. diff --git a/packages/language/test/document.js b/packages/language/test/document.js index 9f00e774c93..8c2dee343dc 100644 --- a/packages/language/test/document.js +++ b/packages/language/test/document.js @@ -57,16 +57,14 @@ describe('Document', function() { }); DocumentCache = extend(true, {}, Document); + DocumentCache.prototype = extend(true, {}, Document.prototype); }); beforeEach(function() { isCustomTypeOverride = null; - for (var property in DocumentCache) { - if (DocumentCache.hasOwnProperty(property)) { - Document[property] = DocumentCache[property]; - } - } + extend(Document, DocumentCache); + Document.prototype = extend({}, DocumentCache.prototype); document = new Document(LANGUAGE, CONFIG); }); @@ -80,6 +78,22 @@ describe('Document', function() { assert(promisified); }); + it('should set the correct encodingType', function() { + var detectedEncodingType = 'detected-encoding-type'; + var config = { + content: CONFIG + }; + + Document.prototype.detectEncodingType_ = function(options) { + assert.strictEqual(options, config); + return detectedEncodingType; + }; + + var document = new Document(LANGUAGE, config); + + assert.strictEqual(document.encodingType, detectedEncodingType); + }); + it('should set the correct document for inline content', function() { assert.deepEqual(document.document, { content: CONFIG, @@ -87,15 +101,6 @@ describe('Document', function() { }); }); - it('should set and uppercase the correct encodingType', function() { - var document = new Document(LANGUAGE, { - content: CONFIG, - encoding: 'utf-8' - }); - - assert.strictEqual(document.encodingType, 'UTF8'); - }); - it('should set the correct document for content with language', function() { var document = new Document(LANGUAGE, { content: CONFIG, @@ -152,6 +157,14 @@ describe('Document', function() { encodeURIComponent(file.id), ].join('')); }); + + it('should default the encodingType to UTF8 if a Buffer', function() { + var document = new Document(LANGUAGE, { + content: new Buffer([]) + }); + + assert.strictEqual(document.encodingType, 'UTF8'); + }); }); describe('LABEL_DESCRIPTIONS', function() { @@ -266,6 +279,13 @@ describe('Document', function() { describe('annotate', function() { it('should make the correct API request', function(done) { + var detectedEncodingType = 'detected-encoding-type'; + + document.detectEncodingType_ = function(options) { + assert.deepEqual(options, {}); + return detectedEncodingType; + }; + document.api.Language = { annotateText: function(reqOpts) { assert.strictEqual(reqOpts.document, document.document); @@ -276,13 +296,12 @@ describe('Document', function() { extractSyntax: true }); - assert.strictEqual(reqOpts.encodingType, document.encodingType); + assert.strictEqual(reqOpts.encodingType, detectedEncodingType); done(); } }; - document.encodingType = 'encoding-type'; document.annotate(assert.ifError); }); @@ -542,15 +561,21 @@ describe('Document', function() { describe('detectEntities', function() { it('should make the correct API request', function(done) { + var detectedEncodingType = 'detected-encoding-type'; + + document.detectEncodingType_ = function(options) { + assert.deepEqual(options, {}); + return detectedEncodingType; + }; + document.api.Language = { analyzeEntities: function(reqOpts) { assert.strictEqual(reqOpts.document, document.document); - assert.strictEqual(reqOpts.encodingType, document.encodingType); + assert.strictEqual(reqOpts.encodingType, detectedEncodingType); done(); } }; - document.encodingType = 'encoding-type'; document.detectEntities(assert.ifError); }); @@ -631,10 +656,17 @@ describe('Document', function() { describe('detectSentiment', function() { it('should make the correct API request', function(done) { + var detectedEncodingType = 'detected-encoding-type'; + + document.detectEncodingType_ = function(options) { + assert.deepEqual(options, {}); + return detectedEncodingType; + }; + document.api.Language = { analyzeSentiment: function(reqOpts) { assert.strictEqual(reqOpts.document, document.document); - assert.strictEqual(reqOpts.encodingType, document.encodingType); + assert.strictEqual(reqOpts.encodingType, detectedEncodingType); done(); } }; @@ -747,10 +779,17 @@ describe('Document', function() { describe('detectSyntax', function() { it('should make the correct API request', function(done) { + var detectedEncodingType = 'detected-encoding-type'; + + document.detectEncodingType_ = function(options) { + assert.deepEqual(options, {}); + return detectedEncodingType; + }; + document.api.Language = { analyzeSyntax: function(reqOpts) { assert.strictEqual(reqOpts.document, document.document); - assert.strictEqual(reqOpts.encodingType, document.encodingType); + assert.strictEqual(reqOpts.encodingType, detectedEncodingType); done(); } }; @@ -1102,4 +1141,69 @@ describe('Document', function() { ); }); }); + + describe('detectEncodingType_', function() { + it('should return if no encoding type is set', function() { + assert.strictEqual(document.detectEncodingType_({ + encoding: '' + }), undefined); + + assert.strictEqual(document.detectEncodingType_({ + encodingType: '' + }), undefined); + + document.encodingType = ''; + assert.strictEqual(document.detectEncodingType_({}), undefined); + }); + + it('should return UTF8 for BUFFER input', function() { + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'buffer' + }), 'UTF8'); + }); + + it('should return UTF16 for STRING input', function() { + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'string' + }), 'UTF16'); + }); + + it('should return original value', function() { + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'UTF32' + }), 'UTF32'); + }); + + it('should capitilize and remove whitespace and hyphens', function() { + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'utf32' + }), 'UTF32'); + + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'UTF 32' + }), 'UTF32'); + + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'UTF-32' + }), 'UTF32'); + }); + + it('should accept options.encoding', function() { + assert.strictEqual(document.detectEncodingType_({ + encoding: 'UTF32' + }), 'UTF32'); + }); + + it('should accept options.encodingType', function() { + assert.strictEqual(document.detectEncodingType_({ + encodingType: 'UTF32' + }), 'UTF32'); + }); + + it('should default to encodingType instance property', function() { + document.encodingType = 'utf-32'; + + assert.strictEqual(document.detectEncodingType_({}), 'UTF32'); + }); + }); });