Skip to content

Instantly share code, notes, and snippets.

View javierfernandes's full-sized avatar

Javier Fernandes javierfernandes

  • Buenos Aires, Argentina
View GitHub Profile
@javierfernandes
javierfernandes / RTT-interpreter-test-after.js
Created August 25, 2020 13:47
[RTT] interpreter test - declarative
describe('Boolean expressions', () => {
[
// not
{ rule: 'not false', gives: true },
{ rule: 'not true', gives: false },
{ rule: 'not not true', gives: true },
// and
{ rule: 'true and true', gives: true },
testFunction(
isWholeBlockSelected,
{
inputToParams: input => {
const state = createState(input)
return [state.getCurrentContent(), state.getSelection()]
},
cases: [
['[>This is some text>]', true],
['T[>his is some text>]', false],
describe('isWholeBlockSelected()', () => {
[
['[>This is some text>]', true],
['T[>his is some text>]', false],
['[>This is some tex>]t', false],
['This is some text', false],
].forEach(([input, expected]) => {
it(`"${input}" = ${expected}`, () => {
describe('isWholeBlockSelected()', () => {
it('should detect whole block was selected', () => {
const state = createState('[>This is some text>]')
expect(isWholeBlockSelected(state.getCurrentContent(), state.getSelection()))
.toBeTrue()
})
it('should say whole block was not selected', () => {
const state = createState('T[>his is some text>]')
expect(isWholeBlockSelected(state.getCurrentContent(), state.getSelection()))
@javierfernandes
javierfernandes / createDescribe.js
Created August 17, 2020 13:49
Higher-order function to create a custom "describe" function keeping the .only/.skip functionality
const internalDescribe = (describeFn, bodyCaller) => (title, body) =>
describeFn(title, () => bodyCaller(body))
const createCustomDescribe = bodyCaller => {
const customDescribe = internalDescribe(describe, bodyCaller)
customDescribe.only = internalDescribe(describe.only, bodyCaller)
customDescribe.skip = internalDescribe(describe.skip, bodyCaller)
return customDescribe
}
describeMongoDB('makeBulkMigration()', ({ getDb }) => {
it('should create a migration that process some updates', async () => {
// prepare some data in db
await getDb().collection('tvshows').insertMany([
{ name: 'hello susan', hour: 19 },
{ name: 'another family night', hour: 22 },
{ name: 'abc', hour: 8 },
{ name: 'telefe news', hour: 12 },
{ name: 'tv attacks', hour: 23 },
@javierfernandes
javierfernandes / describeMongoDB.js
Created August 17, 2020 13:39
Example of a simple custom describe for DB-based tests using mongo and a mock-db impl
export default createDescribe(body => {
let mongoServer
let db
beforeAll(async () => {
mongoServer = new MongoMemoryServer()
db = await mongodbFeature.setup({ config }, await mongoServer.getUri())
})
beforeEach(async () => {
await Promise.all(
@javierfernandes
javierfernandes / Lepifyo.scala
Created May 19, 2019 22:24
O3 - FP+OOP - Lepifyo: en clase (2019c1)
package ar.edu.unq.o3
// modelo
case class Programa(val elementos: List[ElementoPrograma])
trait ElementoPrograma
case class Numero(val valor: Int) extends ElementoPrograma
@javierfernandes
javierfernandes / crear-pr-correccion.sh
Last active May 19, 2019 15:02
Crear-PR-Correccion-Template-Scala
#!/bin/bash
NOMBRE_ENTREGA="checkpoint"
NOMBRE_TAG="checkpoint" # esto podría calcularse segun fecha
COMMIT_BASE="43f7b476bd17df52cee94b4d3d108b5344fd7b46"
# CREAR BASE BRANCH
git checkout -b "${NOMBRE_ENTREGA}-correccion" ${COMMIT_BASE}
git push --set-upstream origin "${NOMBRE_ENTREGA}-correccion"
@javierfernandes
javierfernandes / hogwarts.scala
Created May 11, 2019 14:33
O3 - FP - Pociones - En clase (2019-c1)
package ar.edu.unq.o3
object Hogwarts {
// definiciones de tipos
type Persona = (String, Niveles)
type Niveles = (Int, Int, Int)
type Efecto = Niveles => Niveles