090_sha256_spec.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. -- Tests for sha256() function.
  2. local n = require('test.functional.testnvim')()
  3. local insert, source = n.insert, n.source
  4. local clear, expect = n.clear, n.expect
  5. describe('sha256()', function()
  6. setup(clear)
  7. it('is working', function()
  8. insert('start:')
  9. source([[
  10. let testcase='test for empty string: '
  11. if sha256("") ==# 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
  12. let res='ok'
  13. else
  14. let res='ng'
  15. endif
  16. $put =testcase.res
  17. let testcase='test for 1 char: '
  18. if sha256("a") ==# 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb'
  19. let res='ok'
  20. else
  21. let res='ng'
  22. endif
  23. $put =testcase.res
  24. let testcase='test for 3 chars: '
  25. if sha256("abc") ==# 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
  26. let res='ok'
  27. else
  28. let res='ng'
  29. endif
  30. $put =testcase.res
  31. let testcase='test for contains meta char: '
  32. if sha256("foo\nbar") ==# '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776'
  33. let res='ok'
  34. else
  35. let res='ng'
  36. endif
  37. $put =testcase.res
  38. let testcase='test for contains non-ascii char: '
  39. if sha256("\xde\xad\xbe\xef") ==# '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953'
  40. let res='ok'
  41. else
  42. let res='ng'
  43. endif
  44. $put =testcase.res
  45. ]])
  46. -- Assert buffer contents.
  47. expect([[
  48. start:
  49. test for empty string: ok
  50. test for 1 char: ok
  51. test for 3 chars: ok
  52. test for contains meta char: ok
  53. test for contains non-ascii char: ok]])
  54. end)
  55. end)