Skip to content

Commit

Permalink
feat: add lolwut command (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Jan 31, 2022
1 parent 258d9da commit c5c89c1
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
| [linsert] | :white_check_mark: | :white_check_mark: |
| [llen] | :white_check_mark: | :white_check_mark: |
| [lmove] | :white_check_mark: | :x: |
| [lolwut] | :white_check_mark: | :x: |
| [lolwut] | :white_check_mark: | :white_check_mark: |
| [lpop] | :white_check_mark: | :white_check_mark: |
| [lpos] | :white_check_mark: | :x: |
| [lpush] | :white_check_mark: | :white_check_mark: |
Expand Down
1 change: 1 addition & 0 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export * from './lastsave'
export * from './lindex'
export * from './linsert'
export * from './llen'
export * from './lolwut'
export * from './lpop'
export * from './lpush'
export * from './lpushx'
Expand Down
60 changes: 60 additions & 0 deletions src/commands/lolwut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const redisVersion = '6.2.3'

// schotter, plotter on paper, by Georg Nees
function version5() {
// Using lolwut version 5 20 10
return `⢰⠒⢲⠒⢲⠒⣶⠒⡖⢲⡖⢲⠒⣶⠒⡖⠒⡖⠒⡆
⢸⠒⢺⠒⢺⠒⣿⠒⡗⢺⡗⢺⠒⣿⠒⡗⠒⡗⠒⡇
⡞⠒⣾⣛⣻⣛⣿⢻⡟⢻⠛⣿⢻⡟⢻⠓⢲⣗⣒⡇
⣻⠿⣿⣉⣯⣹⣏⣹⣯⣹⣏⣹⣉⣿⢹⣟⣻⣓⣺⠃
⣌⣉⣿⠭⣧⣸⣏⣹⣯⣯⣯⣯⣽⣯⣿⣉⣹⣄⣸⠀
⣯⣁⣿⣭⣽⣼⣼⡼⣿⣬⣇⣹⡮⣿⣻⣗⣽⣒⡼⡅
⢗⣉⢿⣦⣿⣿⣧⢷⣷⣯⣧⣟⣷⣾⣼⣗⣿⢗⣹⢇
⢳⠞⢺⠶⣿⠾⣟⣻⣾⠟⢷⣟⢾⢷⣿⣓⢧⡧⠴⡎
⡼⠶⡞⢒⡾⠾⡝⢲⡷⡽⢾⣿⢼⣾⢿⠒⣾⡿⠶⡧
⢷⠶⣷⣺⢷⣹⢟⣲⢫⠷⡯⢿⢽⢿⢾⡟⢺⢳⢲⠁
⡸⠺⡺⣺⡻⢾⠞⢛⢶⡻⢞⠾⣹⢿⣾⠙⣻⠛⠺⡀
⠈⠢⠊⠚⠒⠚⠑⠔⠑⠜⠣⠛⠼⠥⠼⠉⠋⠢⠊⠀
Georg Nees - schotter, plotter on paper, 1968. Redis ver. ${redisVersion}`
}

// Plaguemon by hikimori
function version6() {
// Using lolwut version 6 20 10
return `                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
Dedicated to the 8 bit game developers of past and present.
Original 8 bit image from Plaguemon by hikikomori. Redis ver. ${redisVersion}`
}

export function lolwut(VERSION = 'VERSION', version) {
if (VERSION && VERSION.toUpperCase() !== 'VERSION') {
throw new Error('ERR value is not an integer or out of range')
}

// eslint-disable-next-line eqeqeq
if (version == 6) {
return version6()
}

// eslint-disable-next-line eqeqeq
if (version == 5) {
return version5()
}

return version6()
}

export function lolwutBuffer(...args) {
const val = lolwut.apply(this, args)
return val ? Buffer.from(val) : val
}
45 changes: 45 additions & 0 deletions test/integration/commands/lolwut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Redis from 'ioredis'

// eslint-disable-next-line import/no-relative-parent-imports
import { runTwinSuite } from '../../../test-utils'

runTwinSuite('lolwut', command => {
describe(command, () => {
const redis = new Redis()

afterAll(() => {
redis.disconnect()
})

test('should throw on invalid arguments', async () => {
expect.hasAssertions()

try {
await redis[command]('ver', 5)
} catch (err) {
expect(err.message).toMatch('ERR')
}
})

test('should return Plaguemon by hikikomori. by default', async () => {
const result = await redis[command]()
expect(Buffer.isBuffer(result) ? result.toString() : result).toMatch(
'hikikomori'
)
})

test('version 6', async () => {
const result = await redis[command]('version', 6, 20, 10)
expect(Buffer.isBuffer(result) ? result.toString() : result).toMatch(
'hikikomori'
)
})

test('version 5', async () => {
const result = await redis[command]('version', 5, 20, 10)
expect(Buffer.isBuffer(result) ? result.toString() : result).toMatch(
'schotter'
)
})
})
})

0 comments on commit c5c89c1

Please sign in to comment.