aboutsummaryrefslogblamecommitdiffstats
path: root/tests/test-clipboard.js
blob: e1d58280063d1d92513da4efbd16ee8b041c1d77 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        










                                                               
                                                    













                                                                 
                                                    



                                                            



                                                                              



                                                           
                                                            
/*global exports: false, require: false */
/*jslint plusplus: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php

// TODO: add some failing tests as well
"use strict";
var clip = require("clipboard");

var testString = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.\n";
var pushkinTestString = "Byl pozdní večer první máj!\n\nАРИОН.\n\nНас было много на челне;\nИные парус напрягали,\nДругие дружно упирали\nВ глубь мощны веслы. В тишине\nНа руль склонясь, наш кормщик умный\nВ молчаньи правил грузный чолн;\nА я — беспечной веры полн —\nПловцам я пел … Вдруг лоно волн\nИзмял с налету вихорь шумный …\nПогиб и кормщик и пловец! –\nЛишь я, таинственный певец,\nНа берег выброшен грозою,\nЯ гимны прежние пою\nИ ризу влажную мою\nСушу на солнце под скалою.\n";

// TODO: VERY insufficient test, needs to be extended
exports.ensureClipboardASCII = function ensureClipboard(test) {
    var text = "";
    var req = clip.set(testString);
    if (req) {
        text = clip.get();
        if (!text) {
            throw "Cannot read a string from the clipboard";
        }
    } else {
        throw "Cannot copy string to the clipboard";
    }
    test.assertEqual(text, testString,
        "checking set and get clipboard methods (ASCII)");
};

exports.ensureClipboardUnicode = function ensureClipboard(test) {
    var text = "";
    var req = clip.set(pushkinTestString);
    if (req) {
        text = clip.get();
        if (!text) {
            throw "Cannot read a string from the clipboard";
        }
    } else {
        throw "Cannot copy string to the clipboard";
    }
    test.assertEqual(text, pushkinTestString,
        "checking set and get clipboard methods (Unicode)");
};

exports.ensureClipboardGetFlavors = function ensureClipboardGetFlavors(test) {
    clip.set(pushkinTestString);
    var available = clip.getCurrentFlavors();
    test.assertEqual(JSON.stringify(available),'["plain"]',
        "checking getFlavors method");
};

// TODO: test for some weird mimeType which is not supported