38 |
39 | this.handleClick(i)}
42 | />
43 |
44 |
45 |
{status}
46 |
{moves}
47 |
48 |
49 | );
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/test/fixtures/code/input/example.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from flask import (
3 | Blueprint, render_template, session, g, flash, request, redirect, url_for,
4 | current_app
5 | )
6 | from accounts.models import User
7 | from accounts.forms import (
8 | LoginForm, SignupForm, SignupConfirmForm, RecoverPasswordForm,
9 | RecoverPasswordConfirmForm
10 | )
11 | from common.utils import get_signer
12 |
13 |
14 | accounts_app = Blueprint('accounts_app', __name__)
15 |
16 |
17 | @accounts_app.before_app_request
18 | def load_user():
19 | g.user = None
20 | if 'user_id' in session:
21 | try:
22 | g.user = User.objects.get(pk=session['user_id'])
23 | except:
24 | pass
25 |
26 |
27 | @accounts_app.route('/login/', methods=['GET', 'POST'])
28 | def login():
29 | next = request.values.get('next', '/')
30 | form = LoginForm()
31 | form.next.data = next
32 | if form.validate_on_submit():
33 | session['user_id'] = unicode(form.user.pk)
34 | flash(u'Login successfully', 'success')
35 | return redirect(next)
36 | return render_template('accounts/login.html', form=form)
37 |
38 |
39 | @accounts_app.route('/logout/')
40 | def logout():
41 | next = request.args.get('next', '/')
42 | flash(u'Logout successfully', 'success')
43 | session.pop('user_id', None)
44 | return redirect(next)
45 |
46 |
47 | @accounts_app.route('/signup/', methods=['GET', 'POST'])
48 | def signup():
49 | form = SignupForm()
50 | if form.validate_on_submit():
51 | form.save()
52 | flash(
53 | u'Check your email to confirm registration.',
54 | 'success'
55 | )
56 | return redirect(url_for('pages_app.index'))
57 | return render_template('accounts/signup.html', form=form)
58 |
--------------------------------------------------------------------------------
/test/fixtures/code/input/example.rb:
--------------------------------------------------------------------------------
1 | class PasswordResetsController < ApplicationController
2 | before_action :get_user, only: [:edit, :update]
3 | before_action :valid_user, only: [:edit, :update]
4 | before_action :check_expiration, only: [:edit, :update] # Case (1)
5 |
6 | def new
7 | end
8 |
9 | def create
10 | @user = User.find_by(email: params[:password_reset][:email].downcase)
11 | if @user
12 | @user.create_reset_digest
13 | @user.send_password_reset_email
14 | flash[:info] = "Email sent with password reset instructions"
15 | redirect_to root_url
16 | else
17 | flash.now[:danger] = "Email address not found"
18 | render 'new'
19 | end
20 | end
21 |
22 | def edit
23 | end
24 |
25 | def update
26 | if params[:user][:password].empty? # Case (3)
27 | @user.errors.add(:password, :blank)
28 | render 'edit'
29 | elsif @user.update_attributes(user_params) # Case (4)
30 | log_in @user
31 | flash[:success] = "Password has been reset."
32 | redirect_to @user
33 | else
34 | render 'edit' # Case (2)
35 | end
36 | end
37 |
38 | private
39 |
40 | def user_params
41 | params.require(:user).permit(:password, :password_confirmation)
42 | end
43 |
44 | # Before filters
45 |
46 | def get_user
47 | @user = User.find_by(email: params[:email])
48 | end
49 |
50 | # Confirms a valid user.
51 | def valid_user
52 | unless (@user && @user.activated? &&
53 | @user.authenticated?(:reset, params[:id]))
54 | redirect_to root_url
55 | end
56 | end
57 |
58 | # Checks expiration of reset token.
59 | def check_expiration
60 | if @user.password_reset_expired?
61 | flash[:danger] = "Password reset has expired."
62 | redirect_to new_password_reset_url
63 | end
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/test/fixtures/code/output/example.cpp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mplewis/src2png/e20825edaa9153abbf31a18bfe388e9bafebe35a/test/fixtures/code/output/example.cpp.png
--------------------------------------------------------------------------------
/test/fixtures/code/output/example.jsx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mplewis/src2png/e20825edaa9153abbf31a18bfe388e9bafebe35a/test/fixtures/code/output/example.jsx.png
--------------------------------------------------------------------------------
/test/fixtures/code/output/example.py.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mplewis/src2png/e20825edaa9153abbf31a18bfe388e9bafebe35a/test/fixtures/code/output/example.py.png
--------------------------------------------------------------------------------
/test/fixtures/code/output/example.rb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mplewis/src2png/e20825edaa9153abbf31a18bfe388e9bafebe35a/test/fixtures/code/output/example.rb.png
--------------------------------------------------------------------------------
/test/fixtures/images/croppable.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mplewis/src2png/e20825edaa9153abbf31a18bfe388e9bafebe35a/test/fixtures/images/croppable.png
--------------------------------------------------------------------------------
/test/integration/integration_test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # http://redsymbol.net/articles/unofficial-bash-strict-mode/
4 | set -euo pipefail
5 | IFS=$'\n\t'
6 |
7 | ./src2png test/fixtures/code/input/*
8 | test/utils/images_identical tmp/example.cpp.png test/fixtures/code/output/example.cpp.png
9 | test/utils/images_identical tmp/example.jsx.png test/fixtures/code/output/example.jsx.png
10 | test/utils/images_identical tmp/example.py.png test/fixtures/code/output/example.py.png
11 | test/utils/images_identical tmp/example.rb.png test/fixtures/code/output/example.rb.png
12 |
--------------------------------------------------------------------------------
/test/unit/camera_test.js:
--------------------------------------------------------------------------------
1 | const expect = require('chai').expect
2 |
3 | const shell = require('shelljs')
4 | const Jimp = require('jimp')
5 |
6 | const { trim } = require('../../src/camera')
7 |
8 | describe('camera', function () {
9 | describe('trim', function () {
10 | context('with a source image', function () {
11 | const TO_CROP = 'test/tmp/croppable.png'
12 | before(function () {
13 | shell.mkdir('-p', 'test/tmp')
14 | shell.cp('test/fixtures/images/croppable.png', TO_CROP)
15 | })
16 |
17 | it('trims whitespace from images', async function () {
18 | const orig = await Jimp.read(TO_CROP)
19 | expect(orig.bitmap.width).to.eq(200)
20 | expect(orig.bitmap.height).to.eq(200)
21 |
22 | trim(TO_CROP)
23 |
24 | const trimmed = await Jimp.read(TO_CROP)
25 | expect(trimmed.bitmap.width).to.eq(100)
26 | expect(trimmed.bitmap.height).to.eq(100)
27 | })
28 | })
29 | })
30 | })
31 |
--------------------------------------------------------------------------------
/test/utils/images_identical:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | const Jimp = require('jimp')
4 |
5 | // https://medium.com/@dtinth/making-unhandled-promise-rejections-crash-the-node-js-process-ffc27cfcc9dd
6 | process.on('unhandledRejection', err => { throw err })
7 |
8 | function buffersEqual (a, b) {
9 | if (!Buffer.isBuffer(a)) return undefined
10 | if (!Buffer.isBuffer(b)) return undefined
11 | if (typeof a.equals === 'function') return a.equals(b)
12 | if (a.length !== b.length) return false
13 |
14 | for (var i = 0; i < a.length; i++) {
15 | if (a[i] !== b[i]) return false
16 | }
17 |
18 | return true
19 | }
20 |
21 | async function imageData (path) {
22 | const img = await Jimp.read(path)
23 | return img.bitmap.data
24 | }
25 |
26 | async function main () {
27 | const firstPath = process.argv[2]
28 | const secondPath = process.argv[3]
29 | const firstData = await imageData(firstPath)
30 | const secondData = await imageData(secondPath)
31 |
32 | if (!buffersEqual(firstData, secondData)) {
33 | console.error(`Images did not match: ${firstPath}, ${secondPath}`)
34 | process.exit(1)
35 | }
36 |
37 | console.log(`Images identical: ${firstPath}, ${secondPath}`)
38 | }
39 |
40 | main()
41 |
--------------------------------------------------------------------------------
/test/utils/install_fira_code:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # http://redsymbol.net/articles/unofficial-bash-strict-mode/
4 | set -euo pipefail
5 | IFS=$'\n\t'
6 |
7 | # https://github.com/tonsky/FiraCode/issues/4#issuecomment-69215023
8 | mkdir -p ~/.fonts
9 | # changing this hardcoded version of Fira Code may break the pre-captured screenshot fixtures!
10 | wget https://github.com/tonsky/FiraCode/raw/862454fcdaff57c869892d0e82ed348646005444/distr/otf/FiraCode-Regular.otf -O ~/.fonts/FiraCode-Regular.otf
11 | fc-cache -v
12 | fc-list | grep 'Fira Code'
13 |
--------------------------------------------------------------------------------