瀏覽代碼

Add CRLF tests.

Ian Rose 6 年之前
父節點
當前提交
151add8df6
共有 1 個文件被更改,包括 47 次插入0 次删除
  1. 47 0
      tests/test-docregistry/src/context.spec.ts

+ 47 - 0
tests/test-docregistry/src/context.spec.ts

@@ -297,6 +297,42 @@ describe('docregistry/context', () => {
         expect(model.content).to.equal('foo');
         await dismissDialog();
       });
+
+      it('should should preserve LF line endings upon save', async () => {
+        await context.initialize(true);
+        await manager.contents.save(context.path, {
+          type: factory.contentType,
+          format: factory.fileFormat,
+          content: 'foo\nbar'
+        });
+        await context.revert();
+        await context.save();
+        const opts: Contents.IFetchOptions = {
+          format: factory.fileFormat,
+          type: factory.contentType,
+          content: true
+        };
+        const model = await manager.contents.get(context.path, opts);
+        expect(model.content).to.equal('foo\nbar');
+      });
+
+      it('should should preserve CRLF line endings upon save', async () => {
+        await context.initialize(true);
+        await manager.contents.save(context.path, {
+          type: factory.contentType,
+          format: factory.fileFormat,
+          content: 'foo\r\nbar'
+        });
+        await context.revert();
+        await context.save();
+        const opts: Contents.IFetchOptions = {
+          format: factory.fileFormat,
+          type: factory.contentType,
+          content: true
+        };
+        const model = await manager.contents.get(context.path, opts);
+        expect(model.content).to.equal('foo\r\nbar');
+      });
     });
 
     describe('#saveAs()', () => {
@@ -386,6 +422,17 @@ describe('docregistry/context', () => {
         await context.revert();
         expect(context.model.toString()).to.equal('foo');
       });
+
+      it('should normalize CRLF line endings to LF', async () => {
+        await context.initialize(true);
+        await manager.contents.save(context.path, {
+          type: factory.contentType,
+          format: factory.fileFormat,
+          content: 'foo\r\nbar'
+        });
+        await context.revert();
+        expect(context.model.toString()).to.equal('foo\nbar');
+      });
     });
 
     describe('#createCheckpoint()', () => {