clipboard-spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. describe('Clipboard', () => {
  2. describe('write(text, metadata) and read()', () => {
  3. it('writes and reads text to/from the native clipboard', () => {
  4. expect(atom.clipboard.read()).toBe('initial clipboard content');
  5. atom.clipboard.write('next');
  6. expect(atom.clipboard.read()).toBe('next');
  7. });
  8. it('returns metadata if the item on the native clipboard matches the last written item', () => {
  9. atom.clipboard.write('next', { meta: 'data' });
  10. expect(atom.clipboard.read()).toBe('next');
  11. expect(atom.clipboard.readWithMetadata().text).toBe('next');
  12. expect(atom.clipboard.readWithMetadata().metadata).toEqual({
  13. meta: 'data'
  14. });
  15. });
  16. });
  17. describe('line endings', () => {
  18. let originalPlatform = process.platform;
  19. const eols = new Map([
  20. ['win32', '\r\n'],
  21. ['darwin', '\n'],
  22. ['linux', '\n']
  23. ]);
  24. for (let [platform, eol] of eols) {
  25. it(`converts line endings to the OS's native line endings on ${platform}`, () => {
  26. Object.defineProperty(process, 'platform', { value: platform });
  27. atom.clipboard.write('next\ndone\r\n\n', { meta: 'data' });
  28. expect(atom.clipboard.readWithMetadata()).toEqual({
  29. text: `next${eol}done${eol}${eol}`,
  30. metadata: { meta: 'data' }
  31. });
  32. Object.defineProperty(process, 'platform', { value: originalPlatform });
  33. });
  34. }
  35. });
  36. });