How to use the superstring.TextBuffer.prototype function in superstring

To help you get started, we’ve selected a few superstring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atom / text-buffer / spec / text-buffer-io-spec.js View on Github external
it('does not fire duplicate change events when multiple changes happen on disk', async done => {
      const changeEvents = []
      buffer.onWillChange(() => changeEvents.push('will-change'))
      buffer.onDidChange((event) => changeEvents.push('did-change'))

      // We debounce file system change events to avoid redundant loads. But
      // for large files, another file system change event may occur *after* the
      // debounce interval but *before* the previous load has completed. In
      // that scenario, we still want to avoid emitting redundant change events.
      //
      // This test simulates the buffer taking a long time to load and diff by
      // first reading the file's current contents (copying them to a temp file),
      // then waiting for a period of time longer than the debounce interval,
      // and then performing the actual load.
      const originalLoad = buffer.buffer.load
      spyOn(NativeTextBuffer.prototype, 'load').and.callFake(function (pathToLoad, ...args) {
        const pathToLoadCopy = temp.openSync('atom').path
        fs.writeFileSync(pathToLoadCopy, fs.readFileSync(pathToLoad))
        return timeoutPromise(buffer.fileChangeDelay + 100)
          .then(() => originalLoad.call(this, pathToLoadCopy, ...args))
      })

      fs.writeFileSync(filePath, 'a')
      fs.writeFileSync(filePath, 'ab')
      setTimeout(() => {
        fs.writeFileSync(filePath, 'abc')
        fs.writeFileSync(filePath, 'abcd')
        setTimeout(() => {
          fs.writeFileSync(filePath, 'abcde')
          fs.writeFileSync(filePath, 'abcdef')
        }, buffer.fileChangeDelay + 50)
      }, buffer.fileChangeDelay + 50)
github atom / text-buffer / spec / text-buffer-io-spec.js View on Github external
beforeEach(() => {
        const save = NativeTextBuffer.prototype.save

        spyOn(NativeTextBuffer.prototype, 'save').and.callFake(function (destination, encoding) {
          if (destination === filePath) {
            return Promise.reject(Object.assign(new Error('Permission denied'), {code: 'EACCES'}))
          }

          return save.call(this, destination, encoding)
        })
      })

superstring

A data structure to efficiently represent the results of applying patches.

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis