readtoken.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Phoenix Shell.
  5. *
  6. * Phoenix Shell is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import assert from 'assert';
  20. import { readtoken, TOKENS } from '../src/ansi-shell/readline/readtoken.js';
  21. describe('readtoken', () => {
  22. const tcases = [
  23. {
  24. desc: 'should accept unquoted string',
  25. input: 'asdf',
  26. expected: ['asdf']
  27. },
  28. {
  29. desc: 'should accept leading spaces',
  30. input: ' asdf',
  31. expected: ['asdf']
  32. },
  33. {
  34. desc: 'should accept trailing spaces',
  35. input: 'asdf ',
  36. expected: ['asdf']
  37. },
  38. {
  39. desc: 'should expected quoted string',
  40. input: '"asdf"',
  41. expected: ['asdf']
  42. },
  43. {
  44. desc: 'should recognize pipe with no whitespace',
  45. input: 'asdf|zxcv',
  46. expected: ['asdf', TOKENS['|'], 'zxcv']
  47. },
  48. {
  49. desc: 'mixed quoted and unquoted should work',
  50. input: '"asdf" zxcv',
  51. expected: ['asdf', 'zxcv']
  52. },
  53. ];
  54. for ( const { desc, input, expected } of tcases ) {
  55. it(desc, () => {
  56. assert.deepEqual(readtoken(input), expected)
  57. });
  58. }
  59. })