diff --git a/.gitignore b/.gitignore index 0bc8fb85..f124186a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,39 @@ *.pyc *.sw? *~ \#* .\#* /.coverage /.coverage.* .eggs/ resources/test/ __pycache__ version.txt swh.web.egg-info docs/build/ docs/uri-scheme.md docs/dev-info.md *.sqlite3 .vscode/ .directory node_modules/ swh/web/static/*.* swh/web/static/js/ swh/web/static/css/ swh/web/static/fonts/ swh/web/static/jssources/ swh/web/static/img/thirdParty/ .cache-loader/ build/ dist/ .hypothesis .cache .pytest_cache .tox/ debian/ package-lock.json yarn-error.log cypress/mochawesome/ .nyc_output/ cypress/coverage/ +cypress/fixtures/source*.json diff --git a/cypress.json b/cypress.json index 03cacb09..31613afc 100644 --- a/cypress.json +++ b/cypress.json @@ -1,18 +1,19 @@ { "baseUrl": "http://localhost:5004", "video": false, "viewportWidth": 1920, "viewportHeight": 1080, "defaultCommandTimeout": 10000, + "numTestsKeptInMemory": 500, "reporter": "cypress-multi-reporters", "reporterOptions": { "reporterEnabled": "mochawesome", "mochawesomeReporterOptions": { "reportDir": "cypress/mochawesome/results", "quiet": true, "overwrite": false, "html": false, "json": true } } } diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 00000000..da18d935 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} \ No newline at end of file diff --git a/cypress/fixtures/source-file-extensions.json b/cypress/fixtures/source-file-extensions.json deleted file mode 100644 index f9aa1f4d..00000000 --- a/cypress/fixtures/source-file-extensions.json +++ /dev/null @@ -1 +0,0 @@ -["R","abnf","adb","adoc","ads","ahk","aj","applescript","as","au3","awk","bas","bat","bf","bnf","bsl","cal","capnp","cc","ceylon","clj","cls","cmake","coffee","cpp","cr","cs","css","d","dart","dcl","dfm","diff","do","dts","dust","ebnf","elm","ep","erb","erl","ex","exs","f90","feature","flix","fs","gcode","glsl","gml","gms","go","golo","gradle","groovy","gss","haml","hbs","hs","hsp","hx","hy","icl","ini","ino","java","jl","js","json","kt","lasso","lc","ldif","leaf","less","lisp","ll","ls","lsl","lua","m","md","mel","mk","ml","moon","nb","nim","nix","nsi","p","pas","pbi","pde","php","pl","pm","pony","pp","properties","proto","ps1","py","q","qml","rb","re","rib","rs","rsc","s","sas","scad","scala","sci","scm","scss","sh","sl","smali","sml","sqf","st","stan","styl","subunit","swift","tap","tcl","tex","thrift","ts","v","vala","vb","vbs","vhd","vim","wl","xml","xqy","yml","zep"] \ No newline at end of file diff --git a/cypress/fixtures/source-file-names.json b/cypress/fixtures/source-file-names.json deleted file mode 100644 index 5e1bee50..00000000 --- a/cypress/fixtures/source-file-names.json +++ /dev/null @@ -1 +0,0 @@ -[".htaccess","CMakeLists.txt","Dockerfile","Makefile","access.log","httpd.conf","nginx.conf","nginx.log","pf.conf","resolv.conf"] \ No newline at end of file diff --git a/cypress/integration/content-rendering.spec.js b/cypress/integration/content-rendering.spec.js new file mode 100644 index 00000000..1e05411f --- /dev/null +++ b/cypress/integration/content-rendering.spec.js @@ -0,0 +1,102 @@ +/** + * Copyright (C) 2019 The Software Heritage developers + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU Affero General Public License version 3, or any later version + * See top-level LICENSE file for more information + */ + +import {checkLanguageHighlighting} from '../utils'; + +describe('Code highlighting tests', function() { + + const extensions = require('../fixtures/source-file-extensions.json'); + + extensions.forEach(ext => { + it(`should highlight source files with extension ${ext}`, function() { + cy.request(this.Urls.tests_content_code_extension(ext)).then(response => { + let data = response.body; + cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.${ext}`); + checkLanguageHighlighting(data.language); + }); + }); + }); + + const filenames = require('../fixtures/source-file-names.json'); + + filenames.forEach(filename => { + it(`should highlight source files with filenames ${filename}`, function() { + cy.request(this.Urls.tests_content_code_filename(filename)).then(response => { + let data = response.body; + cy.visit(`${this.Urls.browse_content(data.sha1)}?path=${filename}`); + checkLanguageHighlighting(data.language); + }); + }); + }); + +}); + +describe('Image rendering tests', function() { + const imgExtensions = ['gif', 'jpeg', 'png', 'webp']; + + imgExtensions.forEach(ext => { + it(`should render image with extension ${ext}`, function() { + cy.request(this.Urls.tests_content_other_extension(ext)).then(response => { + let data = response.body; + cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.${ext}`); + cy.get('.swh-content img') + .then(img => { + assert.notEqual(img[0].width, 0); + assert.notEqual(img[0].height, 0); + }); + }); + }); + }); + +}); + +describe('PDF rendering test', function() { + + function sum(previousValue, currentValue) { + return previousValue + currentValue; + } + + it(`should render a PDF file`, function() { + cy.request(this.Urls.tests_content_other_extension('pdf')).then(response => { + let data = response.body; + cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.pdf`); + cy.get('.swh-content canvas') + .wait(2000) + .then(canvas => { + let width = canvas[0].width; + let height = canvas[0].height; + let context = canvas[0].getContext('2d'); + let imgData = context.getImageData(0, 0, width, height); + assert.notEqual(imgData.data.reduce(sum), 0); + }); + }); + }); + +}); + +describe('Jupyter notebook rendering test', function() { + + it(`should render a notebook file to HTML`, function() { + cy.request(this.Urls.tests_content_other_extension('ipynb')).then(response => { + let data = response.body; + cy.visit(`${this.Urls.browse_content(data.sha1)}?path=file.ipynb`); + cy.get('.nb-notebook') + .should('be.visible') + .and('not.be.empty'); + cy.get('.nb-cell.nb-markdown-cell') + .should('be.visible') + .and('not.be.empty'); + cy.get('.nb-cell.nb-code-cell') + .should('be.visible') + .and('not.be.empty'); + cy.get('.MathJax') + .should('be.visible') + .and('not.be.empty'); + }); + }); + +}); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 7866302a..eb208b83 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -1,10 +1,26 @@ /** * Copyright (C) 2019 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ +const axios = require('axios'); +const fs = require('fs'); + module.exports = (on, config) => { on('task', require('@cypress/code-coverage/task')); + // produce JSON files prior launching browser in order to dynamically generate tests + on('before:browser:launch', function(browser = {}, args) { + return new Promise((resolve) => { + let p1 = axios.get(`${config.baseUrl}/tests/data/content/code/extensions/`); + let p2 = axios.get(`${config.baseUrl}/tests/data/content/code/filenames/`); + Promise.all([p1, p2]) + .then(function(responses) { + fs.writeFileSync('cypress/fixtures/source-file-extensions.json', JSON.stringify(responses[0].data)); + fs.writeFileSync('cypress/fixtures/source-file-names.json', JSON.stringify(responses[1].data)); + resolve(args); + }); + }); + }); }; diff --git a/cypress/utils/index.js b/cypress/utils/index.js index dc71a4a1..34df946d 100644 --- a/cypress/utils/index.js +++ b/cypress/utils/index.js @@ -1,36 +1,47 @@ /** * Copyright (C) 2019 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ import axios from 'axios'; export async function httpGetJson(url) { const response = await axios.get(url); return response.data; } /** * Converts string with Time information * to an object with Time information */ export function getTime(text) { const date = new Date(text); function pad(n) { return n < 10 ? '0' + n : n; } const time = { date: date.getUTCDate(), month: date.getUTCMonth(), monthName: date.toLocaleString('en', { month: 'long' }), year: date.getUTCFullYear(), hours: pad(date.getUTCHours()), minutes: pad(date.getUTCMinutes()) }; return time; } + +export function checkLanguageHighlighting(language) { + cy.get('code') + .should('be.visible') + .and('have.class', 'hljs') + .and('have.class', language) + .and('not.be.empty') + .find('table.hljs-ln') + .should('be.visible') + .and('not.be.empty'); +} diff --git a/swh/web/config.py b/swh/web/config.py index e6af73a4..5cecf2f4 100644 --- a/swh/web/config.py +++ b/swh/web/config.py @@ -1,154 +1,155 @@ # Copyright (C) 2017-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information import os from swh.core import config from swh.indexer.storage import get_indexer_storage from swh.scheduler import get_scheduler from swh.storage import get_storage from swh.vault import get_vault from swh.web import settings SETTINGS_DIR = os.path.dirname(settings.__file__) DEFAULT_CONFIG = { 'allowed_hosts': ('list', []), 'storage': ('dict', { 'cls': 'remote', 'args': { 'url': 'http://127.0.0.1:5002/', 'timeout': 10, }, }), 'indexer_storage': ('dict', { 'cls': 'remote', 'args': { 'url': 'http://127.0.0.1:5007/', 'timeout': 1, } }), 'log_dir': ('string', '/tmp/swh/log'), 'debug': ('bool', False), 'serve_assets': ('bool', False), 'host': ('string', '127.0.0.1'), 'port': ('int', 5004), 'secret_key': ('string', 'development key'), # do not display code highlighting for content > 1MB 'content_display_max_size': ('int', 5 * 1024 * 1024), 'snapshot_content_max_size': ('int', 1000), 'throttling': ('dict', { 'cache_uri': None, # production: memcached as cache (127.0.0.1:11211) # development: in-memory cache so None 'scopes': { 'swh_api': { 'limiter_rate': { 'default': '120/h' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_vault_cooking': { 'limiter_rate': { 'default': '120/h', 'GET': '60/m' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_save_origin': { 'limiter_rate': { 'default': '120/h', 'POST': '10/h' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_api_origin_visit_latest': { 'limiter_rate': { 'default': '700/m' }, 'exempted_networks': ['127.0.0.0/8'], }, } }), 'vault': ('dict', { 'cls': 'remote', 'args': { 'url': 'http://127.0.0.1:5005/', } }), 'scheduler': ('dict', { 'cls': 'remote', 'args': { 'url': 'http://127.0.0.1:5008/' } }), 'development_db': ('string', os.path.join(SETTINGS_DIR, 'db.sqlite3')), 'production_db': ('string', '/var/lib/swh/web.sqlite3'), 'deposit': ('dict', { 'private_api_url': 'https://deposit.softwareheritage.org/1/private/', 'private_api_user': 'swhworker', 'private_api_password': '' }), - 'coverage_count_origins': ('bool', False) + 'coverage_count_origins': ('bool', False), + 'e2e_tests_mode': ('bool', False) } swhweb_config = {} def get_config(config_file='web/web'): """Read the configuration file `config_file`. If an environment variable SWH_CONFIG_FILENAME is defined, this takes precedence over the config_file parameter. In any case, update the app with parameters (secret_key, conf) and return the parsed configuration as a dict. If no configuration file is provided, return a default configuration. """ if not swhweb_config: config_filename = os.environ.get('SWH_CONFIG_FILENAME') if config_filename: config_file = config_filename cfg = config.load_named_config(config_file, DEFAULT_CONFIG) swhweb_config.update(cfg) config.prepare_folders(swhweb_config, 'log_dir') swhweb_config['storage'] = get_storage(**swhweb_config['storage']) swhweb_config['vault'] = get_vault(**swhweb_config['vault']) swhweb_config['indexer_storage'] = \ get_indexer_storage(**swhweb_config['indexer_storage']) swhweb_config['scheduler'] = get_scheduler( **swhweb_config['scheduler']) return swhweb_config def storage(): """Return the current application's storage. """ return get_config()['storage'] def vault(): """Return the current application's vault. """ return get_config()['vault'] def indexer_storage(): """Return the current application's indexer storage. """ return get_config()['indexer_storage'] def scheduler(): """Return the current application's scheduler. """ return get_config()['scheduler'] diff --git a/swh/web/settings/tests.py b/swh/web/settings/tests.py index 5e83891c..a3becee4 100644 --- a/swh/web/settings/tests.py +++ b/swh/web/settings/tests.py @@ -1,94 +1,95 @@ # Copyright (C) 2017-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information """ Django tests settings for swh-web. """ import sys from swh.web.config import get_config scope1_limiter_rate = 3 scope1_limiter_rate_post = 1 scope2_limiter_rate = 5 scope2_limiter_rate_post = 2 scope3_limiter_rate = 1 scope3_limiter_rate_post = 1 save_origin_rate_post = 10 swh_web_config = get_config() swh_web_config.update({ 'debug': False, 'secret_key': 'test', 'throttling': { 'cache_uri': None, 'scopes': { 'swh_api': { 'limiter_rate': { 'default': '60/min' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_api_origin_visit_latest': { 'limiter_rate': { 'default': '6000/min' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_vault_cooking': { 'limiter_rate': { 'default': '120/h', 'GET': '60/m' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_save_origin': { 'limiter_rate': { 'default': '120/h', 'POST': '%s/h' % save_origin_rate_post, } }, 'scope1': { 'limiter_rate': { 'default': '%s/min' % scope1_limiter_rate, 'POST': '%s/min' % scope1_limiter_rate_post, } }, 'scope2': { 'limiter_rate': { 'default': '%s/min' % scope2_limiter_rate, 'POST': '%s/min' % scope2_limiter_rate_post } }, 'scope3': { 'limiter_rate': { 'default': '%s/min' % scope3_limiter_rate, 'POST': '%s/min' % scope3_limiter_rate_post }, 'exempted_networks': ['127.0.0.0/8'] } } } }) from .common import * # noqa from .common import ALLOWED_HOSTS, LOGGING # noqa # when not running unit tests, make the webapp fetch data from memory storages if 'pytest' not in sys.argv[0]: swh_web_config.update({ 'debug': True, + 'e2e_tests_mode': True }) from swh.web.tests.data import get_tests_data, override_storages # noqa test_data = get_tests_data() override_storages(test_data['storage'], test_data['idx_storage']) else: ALLOWED_HOSTS += ['testserver'] # Silent DEBUG output when running unit tests LOGGING['handlers']['console']['level'] = 'INFO' diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py index 77a83794..876050e8 100644 --- a/swh/web/tests/data.py +++ b/swh/web/tests/data.py @@ -1,322 +1,469 @@ # Copyright (C) 2018-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information from copy import deepcopy import os import random + +from rest_framework.decorators import api_view +from rest_framework.response import Response + from swh.indexer.fossology_license import FossologyLicenseIndexer from swh.indexer.mimetype import MimetypeIndexer from swh.indexer.ctags import CtagsIndexer from swh.indexer.storage import get_indexer_storage +from swh.model.from_disk import Directory from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS from swh.model.identifiers import directory_identifier from swh.loader.git.from_disk import GitLoaderFromArchive from swh.storage.algos.dir_iterators import dir_iterator from swh.web import config from swh.web.browse.utils import ( get_mimetype_and_encoding_for_content, prepare_content_for_display ) from swh.web.common import service +from swh.web.common.highlightjs import get_hljs_language_from_filename # Module used to initialize data that will be provided as tests input # Configuration for git loader _TEST_LOADER_CONFIG = { 'storage': { 'cls': 'memory', 'args': {} }, 'send_contents': True, 'send_directories': True, 'send_revisions': True, 'send_releases': True, 'send_snapshot': True, 'content_size_limit': 100 * 1024 * 1024, 'content_packet_size': 10, 'content_packet_size_bytes': 100 * 1024 * 1024, 'directory_packet_size': 10, 'revision_packet_size': 10, 'release_packet_size': 10, 'save_data': False, } # Base content indexer configuration _TEST_INDEXER_BASE_CONFIG = { 'storage': { 'cls': 'memory', 'args': {}, }, 'objstorage': { 'cls': 'memory', 'args': {}, }, 'indexer_storage': { 'cls': 'memory', 'args': {}, } } def random_sha1(): return hash_to_hex(bytes(random.randint(0, 255) for _ in range(20))) def random_sha256(): return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) def random_blake2s256(): return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) def random_content(): return { 'sha1': random_sha1(), 'sha1_git': random_sha1(), 'sha256': random_sha256(), 'blake2s256': random_blake2s256(), } # MimetypeIndexer with custom configuration for tests class _MimetypeIndexer(MimetypeIndexer): def parse_config_file(self, *args, **kwargs): return { **_TEST_INDEXER_BASE_CONFIG, 'tools': { 'name': 'file', 'version': '1:5.30-1+deb9u1', 'configuration': { "type": "library", "debian-package": "python3-magic" } } } # FossologyLicenseIndexer with custom configuration for tests class _FossologyLicenseIndexer(FossologyLicenseIndexer): def parse_config_file(self, *args, **kwargs): return { **_TEST_INDEXER_BASE_CONFIG, 'workdir': '/tmp/swh/indexer.fossology.license', 'tools': { 'name': 'nomos', 'version': '3.1.0rc2-31-ga2cbb8c', 'configuration': { 'command_line': 'nomossa <filepath>', }, } } # CtagsIndexer with custom configuration for tests class _CtagsIndexer(CtagsIndexer): def parse_config_file(self, *args, **kwargs): return { **_TEST_INDEXER_BASE_CONFIG, 'workdir': '/tmp/swh/indexer.ctags', 'languages': {'c': 'c'}, 'tools': { 'name': 'universal-ctags', 'version': '~git7859817b', 'configuration': { 'command_line': '''ctags --fields=+lnz --sort=no --links=no ''' # noqa '''--output-format=json <filepath>''' }, } } # Lightweight git repositories that will be loaded to generate # input data for tests _TEST_ORIGINS = [ { 'type': 'git', 'url': 'https://github.com/wcoder/highlightjs-line-numbers.js', 'archives': ['highlightjs-line-numbers.js.zip', 'highlightjs-line-numbers.js_visit2.zip'], 'visit_date': ['Dec 1 2018, 01:00 UTC', 'Jan 20 2019, 15:00 UTC'] }, { 'type': 'git', 'url': 'https://github.com/memononen/libtess2', 'archives': ['libtess2.zip'], 'visit_date': ['May 25 2018, 01:00 UTC'] }, { 'type': 'git', 'url': 'repo_with_submodules', 'archives': ['repo_with_submodules.tgz'], 'visit_date': ['Jan 1 2019, 01:00 UTC'] } ] _contents = {} # Tests data initialization def _init_tests_data(): # Load git repositories from archives loader = GitLoaderFromArchive(config=_TEST_LOADER_CONFIG) # Get reference to the memory storage storage = loader.storage for origin in _TEST_ORIGINS: for i, archive in enumerate(origin['archives']): origin_repo_archive = \ os.path.join(os.path.dirname(__file__), 'resources/repos/%s' % archive) loader.load(origin['url'], origin_repo_archive, origin['visit_date'][i]) origin.update(storage.origin_get(origin)) # add an 'id' key if enabled contents = set() directories = set() revisions = set() releases = set() snapshots = set() persons = set() content_path = {} # Get all objects loaded into the test archive for origin in _TEST_ORIGINS: snp = storage.snapshot_get_latest(origin['url']) snapshots.add(hash_to_hex(snp['id'])) for branch_name, branch_data in snp['branches'].items(): if branch_data['target_type'] == 'revision': revisions.add(branch_data['target']) elif branch_data['target_type'] == 'release': release = next(storage.release_get([branch_data['target']])) revisions.add(release['target']) releases.add(hash_to_hex(branch_data['target'])) persons.add(release['author']['id']) for rev_log in storage.revision_shortlog(set(revisions)): rev_id = rev_log[0] revisions.add(rev_id) for rev in storage.revision_get(revisions): dir_id = rev['directory'] persons.add(rev['author']['id']) persons.add(rev['committer']['id']) directories.add(hash_to_hex(dir_id)) for entry in dir_iterator(storage, dir_id): content_path[entry['sha1']] = '/'.join( [hash_to_hex(dir_id), entry['path'].decode('utf-8')]) if entry['type'] == 'file': contents.add(entry['sha1']) elif entry['type'] == 'dir': directories.add(hash_to_hex(entry['target'])) # Get all checksums for each content contents_metadata = storage.content_get_metadata(contents) contents = [] for content_metadata in contents_metadata: contents.append({ algo: hash_to_hex(content_metadata[algo]) for algo in DEFAULT_ALGORITHMS }) path = content_path[content_metadata['sha1']] cnt = next(storage.content_get([content_metadata['sha1']])) mimetype, encoding = get_mimetype_and_encoding_for_content(cnt['data']) content_display_data = prepare_content_for_display( cnt['data'], mimetype, path) contents[-1]['path'] = path contents[-1]['mimetype'] = mimetype contents[-1]['encoding'] = encoding contents[-1]['hljs_language'] = content_display_data['language'] contents[-1]['data'] = content_display_data['content_data'] _contents[contents[-1]['sha1']] = contents[-1] # Create indexer storage instance that will be shared by indexers idx_storage = get_indexer_storage('memory', {}) # Add the empty directory to the test archive empty_dir_id = directory_identifier({'entries': []}) empty_dir_id_bin = hash_to_bytes(empty_dir_id) storage.directory_add([{'id': empty_dir_id_bin, 'entries': []}]) # Return tests data return { 'storage': storage, 'idx_storage': idx_storage, 'origins': _TEST_ORIGINS, 'contents': contents, 'directories': list(directories), 'persons': list(persons), 'releases': list(releases), 'revisions': list(map(hash_to_hex, revisions)), 'snapshots': list(snapshots), 'generated_checksums': set(), } def _init_indexers(tests_data): # Instantiate content indexers that will be used in tests # and force them to use the memory storages indexers = {} for idx_name, idx_class in (('mimetype_indexer', _MimetypeIndexer), ('license_indexer', _FossologyLicenseIndexer), ('ctags_indexer', _CtagsIndexer)): idx = idx_class() idx.storage = tests_data['storage'] idx.objstorage = tests_data['storage'].objstorage idx.idx_storage = tests_data['idx_storage'] idx.register_tools(idx.config['tools']) indexers[idx_name] = idx return indexers def get_content(content_sha1): return _contents.get(content_sha1) _tests_data = None _current_tests_data = None _indexer_loggers = {} def get_tests_data(reset=False): """ Initialize tests data and return them in a dict. """ global _tests_data, _current_tests_data if _tests_data is None: _tests_data = _init_tests_data() indexers = _init_indexers(_tests_data) for (name, idx) in indexers.items(): # pytest makes the loggers use a temporary file; and deepcopy # requires serializability. So we remove them, and add them # back after the copy. _indexer_loggers[name] = idx.log del idx.log _tests_data.update(indexers) if reset or _current_tests_data is None: _current_tests_data = deepcopy(_tests_data) for (name, logger) in _indexer_loggers.items(): _current_tests_data[name].log = logger return _current_tests_data def override_storages(storage, idx_storage): """ Helper function to replace the storages from which archive data are fetched. """ swh_config = config.get_config() swh_config.update({'storage': storage}) service.storage = storage swh_config.update({'indexer_storage': idx_storage}) service.idx_storage = idx_storage + + +# Implement some special endpoints used to provide input tests data +# when executing end to end tests with cypress + +_content_code_data_exts = {} +_content_code_data_filenames = {} +_content_other_data_exts = {} + + +def _init_content_tests_data(data_path, data_dict, ext_key): + """ + Helper function to read the content of a directory, store it + into a test archive and add some files metadata (sha1 and/or + expected programming language) in a dict. + + Args: + data_path (str): path to a directory relative to the tests + folder of swh-web + data_dict (dict): the dict that will store files metadata + ext_key (bool): whether to use file extensions or filenames + as dict keys + """ + test_contents_dir = os.path.join( + os.path.dirname(__file__), data_path).encode('utf-8') + directory = Directory.from_disk(path=test_contents_dir, data=True, + save_path=True) + objects = directory.collect() + for c in objects['content'].values(): + c['status'] = 'visible' + sha1 = hash_to_hex(c['sha1']) + if ext_key: + key = c['path'].decode('utf-8').split('.')[-1] + filename = 'test.' + key + else: + filename = c['path'].decode('utf-8').split('/')[-1] + key = filename + language = get_hljs_language_from_filename(filename) + data_dict[key] = {'sha1': sha1, + 'language': language} + storage = get_tests_data()['storage'] + storage.content_add(objects['content'].values()) + + +def _init_content_code_data_exts(): + """ + Fill a global dictionary which maps source file extension to + a code content example. + """ + global _content_code_data_exts + _init_content_tests_data('resources/contents/code/extensions', + _content_code_data_exts, True) + + +def _init_content_other_data_exts(): + """ + Fill a global dictionary which maps a file extension to + a content example. + """ + global _content_other_data_exts + _init_content_tests_data('resources/contents/other/extensions', + _content_other_data_exts, True) + + +def _init_content_code_data_filenames(): + """ + Fill a global dictionary which maps a filename to + a content example. + """ + global _content_code_data_filenames + _init_content_tests_data('resources/contents/code/filenames', + _content_code_data_filenames, False) + + +if config.get_config()['e2e_tests_mode']: + _init_content_code_data_exts() + _init_content_other_data_exts() + _init_content_code_data_filenames() + + +@api_view(['GET']) +def get_content_code_data_all_exts(request): + """ + Endpoint implementation returning a list of all source file + extensions to test for highlighting using cypress. + """ + return Response(sorted(_content_code_data_exts.keys()), + status=200, content_type='application/json') + + +@api_view(['GET']) +def get_content_code_data_by_ext(request, ext): + """ + Endpoint implementation returning metadata of a code content example + based on the source file extension. + """ + data = None + status = 404 + if ext in _content_code_data_exts: + data = _content_code_data_exts[ext] + status = 200 + return Response(data, status=status, content_type='application/json') + + +@api_view(['GET']) +def get_content_other_data_by_ext(request, ext): + """ + Endpoint implementation returning metadata of a content example + based on the file extension. + """ + _init_content_other_data_exts() + data = None + status = 404 + if ext in _content_other_data_exts: + data = _content_other_data_exts[ext] + status = 200 + return Response(data, status=status, content_type='application/json') + + +@api_view(['GET']) +def get_content_code_data_all_filenames(request): + """ + Endpoint implementation returning a list of all source filenames + to test for highlighting using cypress. + """ + return Response(sorted(_content_code_data_filenames.keys()), + status=200, content_type='application/json') + + +@api_view(['GET']) +def get_content_code_data_by_filename(request, filename): + """ + Endpoint implementation returning metadata of a code content example + based on the source filename. + """ + data = None + status = 404 + if filename in _content_code_data_filenames: + data = _content_code_data_filenames[filename] + status = 200 + return Response(data, status=status, content_type='application/json') diff --git a/swh/web/tests/resources/contents/code/LICENSE b/swh/web/tests/resources/contents/code/LICENSE new file mode 100644 index 00000000..cf0f4de9 --- /dev/null +++ b/swh/web/tests/resources/contents/code/LICENSE @@ -0,0 +1,28 @@ +All the test source files are taken from the highlight.js demo website +(see https://highlightjs.org/static/demo/ and + https://github.com/highlightjs/highlight.js/tree/master/test/detect) + +Copyright (c) 2006, Ivan Sagalaev +All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of highlight.js nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/swh/web/tests/resources/contents/code/extensions/test.R b/swh/web/tests/resources/contents/code/extensions/test.R new file mode 100644 index 00000000..d9e5175d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.R @@ -0,0 +1,68 @@ +library(ggplot2) + +centre <- function(x, type, ...) { + switch(type, + mean = mean(x), + median = median(x), + trimmed = mean(x, trim = .1)) +} + +myVar1 +myVar.2 +data$x +foo "bar" baz +# test "test" +"test # test" + +(123) (1) (10) (0.1) (.2) (1e-7) +(1.2e+7) (2e) (3e+10) (0x0) (0xa) +(0xabcdef1234567890) (123L) (1L) +(0x10L) (10000000L) (1e6L) (1.1L) +(1e-3L) (4123.381E-10i) +(3.) (3.E10) # BUG: .E10 should be part of number + +# Numbers in some different contexts +1L +0x40 +.234 +3. +1L + 30 +plot(cars, xlim=20) +plot(cars, xlim=0x20) +foo<-30 +my.data.3 <- read() # not a number +c(1,2,3) +1%%2 + +"this is a quote that spans +multiple lines +\" + +is this still a quote? it should be. +# even still! + +" # now we're done. + +'same for +single quotes #' + +# keywords +NULL, NA, TRUE, FALSE, Inf, NaN, NA_integer_, +NA_real_, NA_character_, NA_complex_, function, +while, repeat, for, if, in, else, next, break, +..., ..1, ..2 + +# not keywords +the quick brown fox jumped over the lazy dogs +null na true false inf nan na_integer_ na_real_ +na_character_ na_complex_ Function While Repeat +For If In Else Next Break .. .... "NULL" `NULL` 'NULL' + +# operators ++, -, *, /, %%, ^, >, >=, <, <=, ==, !=, !, &, |, ~, +->, <-, <<-, $, :, :: + +# infix operator +foo %union% bar +%"test"% +`"test"` \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.abnf b/swh/web/tests/resources/contents/code/extensions/test.abnf new file mode 100644 index 00000000..4fba0e39 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.abnf @@ -0,0 +1,22 @@ +; line comment + +ruleset = [optional] *(group1 / group2 / SP) CRLF ; trailing comment + +group1 = alt1 +group1 =/ alt2 + +alt1 = %x41-4D / %d78-90 + +alt2 = %b00100001 + +group2 = *1DIGIT / 2*HEXDIG / 3*4OCTET + +optional = hex-codes + / literal + / sensitive + / insensitive + +hex-codes = %x68.65.6C.6C.6F +literal = "string literal" +sensitive = %s"case-sensitive string" +insensitive = %i"case-insensitive string" diff --git a/swh/web/tests/resources/contents/code/extensions/test.adb b/swh/web/tests/resources/contents/code/extensions/test.adb new file mode 100644 index 00000000..09318ae0 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.adb @@ -0,0 +1,17 @@ +package body Sqlite.Simple is + + Foo : int := int'Size; + Bar : int := long'Size; + + Error_Message_C : chars_ptr := Sqlite_Errstr (Error); + Error_Message : String := Null_Ignore_Value (Error_Message_C); + begin + + Named : for Index in Foo..Bar loop + Put ("Hi[]{}"); + end loop Named; + + Foo := Bar; + end Message; + +end Sqlite.Simple; diff --git a/swh/web/tests/resources/contents/code/extensions/test.adoc b/swh/web/tests/resources/contents/code/extensions/test.adoc new file mode 100644 index 00000000..2af6ee6c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.adoc @@ -0,0 +1,65 @@ +Hello, World! +============ +Author Name, <author@domain.foo> + +you can write text http://example.com[with links], optionally +using an explicit link:http://example.com[link prefix]. + +* single quotes around a phrase place 'emphasis' +** alternatively, you can put underlines around a phrase to add _emphasis_ +* astericks around a phrase make the text *bold* +* pluses around a phrase make it +monospaced+ +* `smart' quotes using a leading backtick and trailing single quote +** use two of each for double ``smart'' quotes + +- escape characters are supported +- you can escape a quote inside emphasized text like 'here\'s johnny!' + +term:: definition + another term:: another definition + +// this is just a comment + +Let's make a break. + +''' + +//// +we'll be right with you + +after this brief interruption. +//// + +== We're back! + +Want to see a image::images/tiger.png[Tiger]? + +.Nested highlighting +++++ +<this_is inline="xml"></this_is> +++++ + +____ +asciidoc is so powerful. +____ + +another quote: + +[quote, Sir Arthur Conan Doyle, The Adventures of Sherlock Holmes] +____ +When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth. +____ + +Getting Literal +--------------- + + want to get literal? prefix a line with a space. + +.... +I'll join that party, too. +.... + +. one thing (yeah!) +. two thing `i can write code`, and `more` wipee! + +NOTE: AsciiDoc is quite cool, you should try it. \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ahk b/swh/web/tests/resources/contents/code/extensions/test.ahk new file mode 100644 index 00000000..113ffdc3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ahk @@ -0,0 +1,24 @@ +; hotkeys and hotstrings +#a::WinSet, AlwaysOnTop, Toggle, A +#Space:: + MsgBox, Percent sign (`%) need to be escaped. + Run "C:\Program Files\some\program.exe" + Gosub, label1 +return +::btw::by the way +; volume +#Numpad8::Send {Volume_Up} +#Numpad5::Send {Volume_Mute} +#Numpad2::Send {Volume_Down} + +label1: + if (Clipboard = "") + { + MsgBox, , Clipboard, Empty! + } + else + { + StringReplace, temp, Clipboard, old, new, All + MsgBox, , Clipboard, %temp% + } +return \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.aj b/swh/web/tests/resources/contents/code/extensions/test.aj new file mode 100644 index 00000000..4cc90bef --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.aj @@ -0,0 +1,23 @@ +package com.aspectj.syntax; +import org.aspectj.lang.annotation.AdviceName; + +privileged public aspect LoggingAspect percflowbelow(ajia.services.*){ + private pointcut getResult() : call(* *(..) throws SQLException) && args(Account, .., int); + @AdviceName("CheckValidEmail") + before (Customer hu) : getResult(hu){ + System.out.println("Your mail address is valid!"); + } + Object around() throws InsufficientBalanceException: getResult() && call(Customer.new(String,String,int,int,int)){ + return proceed(); + } + public Cache getCache() { + return this.cache; + } + pointcut beanPropertyChange(BeanSupport bean, Object newValue): execution(void BeanSupport+.set*(*)) && args(newValue) && this(bean); + declare parents: banking.entities.* implements BeanSupport; + declare warning : call(void TestSoftening.perform()): "Please ensure you are not calling this from an AWT thread"; + private String Identifiable.id; + public void Identifiable.setId(String id) { + this.id = id; + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.applescript b/swh/web/tests/resources/contents/code/extensions/test.applescript new file mode 100644 index 00000000..c43e88ec --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.applescript @@ -0,0 +1,14 @@ +repeat 5 times + if foo is greater than bar then + display dialog "Hello there" + else + beep + end if +end repeat + +(* comment (*nested comment*) *) +on do_something(s, y) + return {s + pi, y mod 4} +end do_something + +do shell script "/bin/echo 'hello'" \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.as b/swh/web/tests/resources/contents/code/extensions/test.as new file mode 100644 index 00000000..b416de8e --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.as @@ -0,0 +1,24 @@ +package org.example.dummy { + import org.dummy.*; + + /*define package inline interface*/ + public interface IFooBarzable { + public function foo(... pairs):Array; + } + + public class FooBar implements IFooBarzable { + static private var cnt:uint = 0; + private var bar:String; + + //constructor + public function TestBar(bar:String):void { + bar = bar; + ++cnt; + } + + public function foo(... pairs):Array { + pairs.push(bar); + return pairs; + } + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.au3 b/swh/web/tests/resources/contents/code/extensions/test.au3 new file mode 100644 index 00000000..7946a548 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.au3 @@ -0,0 +1,16 @@ +#NoTrayIcon +#AutoIt3Wrapper_Run_Tidy=Y +#include <Misc.au3> + +_Singleton(@ScriptName) ; Allow only one instance +example(0, 10) + +Func example($min, $max) + For $i = $min To $max + If Mod($i, 2) == 0 Then + MsgBox(64, "Message", $i & ' is even number!') + Else + MsgBox(64, "Message", $i & ' is odd number!') + EndIf + Next +EndFunc ;==>example \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.awk b/swh/web/tests/resources/contents/code/extensions/test.awk new file mode 100644 index 00000000..8909d618 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.awk @@ -0,0 +1,16 @@ +BEGIN { + POPService = "/inet/tcp/0/emailhost/pop3" + RS = ORS = "\r\n" + print "user name" |& POPService + POPService |& getline + print "pass password" |& POPService + POPService |& getline + print "retr 1" |& POPService + POPService |& getline + if ($1 != "+OK") exit + print "quit" |& POPService + RS = "\r\n\\.\r\n" + POPService |& getline + print $0 + close(POPService) +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.bas b/swh/web/tests/resources/contents/code/extensions/test.bas new file mode 100644 index 00000000..04db6deb --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.bas @@ -0,0 +1,22 @@ +10 CLS +20 FOR I = 0 TO 15 +22 FOR J = 0 TO 7 +30 COLOR I,J +40 PRINT " ** "; +45 NEXT J +46 COLOR I,0 +47 GOSUB 100 +48 PRINT +50 NEXT I +60 COLOR 15,0 +99 END +100 FOR T = 65 TO 90 +101 PRINT CHR$(T); +102 NEXT T +103 RETURN +200 REM Data types test +201 TOTAL# = 3.30# 'Double precision variable +202 BALANCE! = 3! 'Single precision variable +203 B2! = 12e5 '120000 +204 ITEMS% = 10 'Integer variable +205 HEXTEST = &H12DB 'Hex value diff --git a/swh/web/tests/resources/contents/code/extensions/test.bat b/swh/web/tests/resources/contents/code/extensions/test.bat new file mode 100644 index 00000000..d911fed3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.bat @@ -0,0 +1,24 @@ +cd \ +copy a b +ping 192.168.0.1 +@rem ping 192.168.0.1 +net stop sharedaccess +del %tmp% /f /s /q +del %temp% /f /s /q +ipconfig /flushdns +taskkill /F /IM JAVA.EXE /T + +cd Photoshop/Adobe Photoshop CS3/AMT/ +if exist application.sif ( + ren application.sif _application.sif +) else ( + ren _application.sif application.sif +) + +taskkill /F /IM proquota.exe /T + +sfc /SCANNOW + +set path = test + +xcopy %1\*.* %2 \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.bf b/swh/web/tests/resources/contents/code/extensions/test.bf new file mode 100644 index 00000000..5156af02 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.bf @@ -0,0 +1,17 @@ +++++++++++ +[ 3*10 and 10*10 + ->+++>++++++++++<< +]>> +[ filling cells + ->++>>++>++>+>++>>++>++>++>++>++>++>++>++>++>++>++[</]<[<]<[<]>> +]< ++++++++++<< +[ rough codes correction loop + ->>>+>+>+>+++>+>+>+>+>+>+>+>+>+>+>+>+>+>+[<]< +] +more accurate сodes correction +>>>++> +-->+++++++>------>++++++>++>+++++++++>++++++++++>++++++++>--->++++++++++>------>++++++> +++>+++++++++++>++++++++++++>------>+++ +rewind and output +[<]>[.>] diff --git a/swh/web/tests/resources/contents/code/extensions/test.bnf b/swh/web/tests/resources/contents/code/extensions/test.bnf new file mode 100644 index 00000000..2149c65d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.bnf @@ -0,0 +1,8 @@ +<syntax> ::= <rule> | <rule> <syntax> +<rule> ::= <opt-whitespace> "<" <rule-name> ">" <opt-whitespace> "::=" <opt-whitespace> <expression> <line-end> +<opt-whitespace> ::= " " <opt-whitespace> | "" +<expression> ::= <list> | <list> <opt-whitespace> "|" <opt-whitespace> <expression> +<line-end> ::= <opt-whitespace> <EOL> | <line-end> <line-end> +<list> ::= <term> | <term> <opt-whitespace> <list> +<term> ::= <literal> | "<" <rule-name> ">" +<literal> ::= '"' <text> '"' | "'" <text> "'" diff --git a/swh/web/tests/resources/contents/code/extensions/test.bsl b/swh/web/tests/resources/contents/code/extensions/test.bsl new file mode 100644 index 00000000..d6dc7aac --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.bsl @@ -0,0 +1,30 @@ +#ЗагрузитьИзФайла ext_module.txt // директива 7.7 +#Если Клиент ИЛИ НаКлиенте Тогда // инструкции препроцессора + &НаКлиентеНаСервереБезКонтекста // директивы компиляции + Функция ТолстыйКлиентОбычноеПриложение(Знач Параметр1 = Неопределено, // комментарий + Параметр2 = "", ПараметрN = 123.45, ПарамNN) Экспорт // еще комментарий + Попытка + Результат_Булевы_Значения = Новый Структура("П1, П2", Истина, Ложь, NULL, Неопределено); + Перейти ~МеткаGOTO; // комментарий + РезультатТаблицаДат = Новый ТаблицаЗначений; + РезультатТаблицаДат.Колонки.Добавить("Колонка1", + Новый ОписаниеТипов("Дата", , , + Новый КвалификаторыДаты(ЧастиДаты.ДатаВремя)); + НС = РезультатТаблицаДат.Добавить(); НС["Колонка1"] = '20170101120000'); + Исключение + ОписаниеОшибки = ОписаниеОшибки(); // встроенная функция + Масс = Новый Массив; // встроенный тип + Для Каждого Значение Из Масс Цикл + Сообщить(Значение + Символы.ПС + " + |продолжение строки"); // продолжение многострочной строки + Продолжить; Прервать; + КонецЦикла; + СправочникСсылка = Справочники.Языки.НайтиПоНаименованию("ru"); // встроенные типы + СправочникОбъект = СправочникСсылка.ПолучитьОбъект(); + ПеречислениеСсылка = Перечисления.ВидыМодификацииДанных.Изменен; + ВызватьИсключение ОписаниеОшибки; + КонецПопытки; + ~МеткаGOTO: // еще комментарий + ВД = ВидДвиженияБухгалтерии.Дебет; + КонецФункции // ТолстыйКлиентОбычноеПриложение() +#КонецЕсли \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.cal b/swh/web/tests/resources/contents/code/extensions/test.cal new file mode 100644 index 00000000..5eec86ca --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.cal @@ -0,0 +1,33 @@ +OBJECT Codeunit 11 Gen. Jnl.-Check Line +{ + OBJECT-PROPERTIES + { + Date=09-09-14; + Time=12:00:00; + Version List=NAVW18.00; + } + PROPERTIES + { + TableNo=81; + Permissions=TableData 252=rimd; + OnRun=BEGIN + GLSetup.GET; + RunCheck(Rec); + END; + + } + CODE + { + VAR + Text000@1000 : TextConst 'ENU=can only be a closing date for G/L entries'; + Text001@1001 : TextConst 'ENU=is not within your range of allowed posting dates'; + + PROCEDURE ErrorIfPositiveAmt@2(GenJnlLine@1000 : Record 81); + BEGIN + IF GenJnlLine.Amount > 0 THEN + GenJnlLine.FIELDERROR(Amount,Text008); + END; + + LOCAL PROCEDURE CheckGenJnlLineDocType@7(GenJnlLine@1001 : Record 81); + } +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.capnp b/swh/web/tests/resources/contents/code/extensions/test.capnp new file mode 100644 index 00000000..f57fbea0 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.capnp @@ -0,0 +1,55 @@ +@0xdbb9ad1f14bf0b36; # unique file ID, generated by `capnp id` + +struct Person { + name @0 :Text; + birthdate @3 :Date; + + email @1 :Text; + phones @2 :List(PhoneNumber); + + struct PhoneNumber { + number @0 :Text; + type @1 :Type; + + enum Type { + mobile @0; + home @1; + work @2; + } + } +} + +struct Date { + year @0 :Int16; + month @1 :UInt8; + day @2 :UInt8; + flags @3 :List(Bool) = [ true, false, false, true ]; +} + +interface Node { + isDirectory @0 () -> (result :Bool); +} + +interface Directory extends(Node) { + list @0 () -> (list: List(Entry)); + struct Entry { + name @0 :Text; + node @1 :Node; + } + + create @1 (name :Text) -> (file :File); + mkdir @2 (name :Text) -> (directory :Directory) + open @3 (name :Text) -> (node :Node); + delete @4 (name :Text); + link @5 (name :Text, node :Node); +} + +interface File extends(Node) { + size @0 () -> (size: UInt64); + read @1 (startAt :UInt64 = 0, amount :UInt64 = 0xffffffffffffffff) + -> (data: Data); + # Default params = read entire file. + + write @2 (startAt :UInt64, data :Data); + truncate @3 (size :UInt64); +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ceylon b/swh/web/tests/resources/contents/code/extensions/test.ceylon new file mode 100644 index 00000000..814079f7 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ceylon @@ -0,0 +1,8 @@ +shared void run() { + print("Hello, `` process.arguments.first else "World" ``!"); +} +class Counter(count=0) { + variable Integer count; + shared Integer currentValue => count; + shared void increment() => count++; +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.clj b/swh/web/tests/resources/contents/code/extensions/test.clj new file mode 100644 index 00000000..55768f37 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.clj @@ -0,0 +1,11 @@ +(def ^:dynamic chunk-size 17) + +(defn next-chunk [rdr] + (let [buf (char-array chunk-size) + s (.read rdr buf)] + (when (pos? s) + (java.nio.CharBuffer/wrap buf 0 s)))) + +(defn chunk-seq [rdr] + (when-let [chunk (next-chunk rdr)] + (cons chunk (lazy-seq (chunk-seq rdr))))) \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.cls b/swh/web/tests/resources/contents/code/extensions/test.cls new file mode 100644 index 00000000..52924f13 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.cls @@ -0,0 +1,21 @@ +#dim test as %Library.Integer +SET test = 123.099 +set ^global = %request.Content +Write "Current date """, $ztimestamp, """, result: ", test + ^global = 125.099 +do ##class(Cinema.Utils).AddShow("test") // class method call +do ##super() ; another one-line comment +d:(^global = 2) ..thisClassMethod(1, 2, "test") +/* + * Sub-languages support: + */ +&sql( SELECT * FROM Cinema.Film WHERE Length > 2 ) +&js<for (var i = 0; i < String("test").split("").length); ++i) { + console.log(i); +}> +&html<<!DOCTYPE html> +<html> +<head> <meta name="test"/> </head> +<body>Test</body> +</html>> + +quit $$$OK diff --git a/swh/web/tests/resources/contents/code/extensions/test.cmake b/swh/web/tests/resources/contents/code/extensions/test.cmake new file mode 100644 index 00000000..2bbea38c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.cmake @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.8) +project(cmake_example) + +# Show message on Linux platform +if (${CMAKE_SYSTEM_NAME} MATCHES Linux) + message("Good choice, bro!") +endif() + +# Tell CMake to run moc when necessary: +set(CMAKE_AUTOMOC ON) +# As moc files are generated in the binary dir, +# tell CMake to always look for includes there: +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Widgets finds its own dependencies. +find_package(Qt5Widgets REQUIRED) + +add_executable(myproject main.cpp mainwindow.cpp) +qt5_use_modules(myproject Widgets) diff --git a/swh/web/tests/resources/contents/code/extensions/test.coffee b/swh/web/tests/resources/contents/code/extensions/test.coffee new file mode 100644 index 00000000..e4eeb954 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.coffee @@ -0,0 +1,13 @@ +grade = (student, period=(if b? then 7 else 6)) -> + if student.excellentWork + "A+" + else if student.okayStuff + if student.triedHard then "B" else "B-" + else + "C" + +class Animal extends Being + constructor: (@name) -> + + move: (meters) -> + alert @name + " moved #{meters}m." \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.cpp b/swh/web/tests/resources/contents/code/extensions/test.cpp new file mode 100644 index 00000000..6c4ef13c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.cpp @@ -0,0 +1,18 @@ +#include <iostream> +#include <unordered_map> +#include <vector> + +using namespace std; + +int main(int argc, char *argv[]) { + + /* An annoying "Hello World" example */ + for (auto i = 0; i < 0xFFFF; i++) + cout << "Hello, World!" << endl; + + char c = '\n'; + unordered_map<string, vector<string>> m; + m["key"] = "\\\\"; // this is an error + + return -2e3 + 12l; +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.cr b/swh/web/tests/resources/contents/code/extensions/test.cr new file mode 100644 index 00000000..e55ddaba --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.cr @@ -0,0 +1,29 @@ +class Person + def initialize(@name : String) + end + + def greet + puts "Hi, I'm #{@name}" + end +end + +class Employee < Person +end + +employee = Employee.new "John" +employee.greet # => "Hi, I'm John" +employee.is_a?(Person) # => true + +@[Link("m")] +lib C + # In C: double cos(double x) + fun cos(value : Float64) : Float64 +end + +C.cos(1.5_f64) # => 0.0707372 + +s = uninitialized String +s = <<-'STR' +\hello\world +\hello\world +STR \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.cs b/swh/web/tests/resources/contents/code/extensions/test.cs new file mode 100644 index 00000000..b47e781e --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.cs @@ -0,0 +1,16 @@ +using System.IO.Compression; + +#pragma warning disable 414, 3021 + +namespace MyApplication +{ + [Obsolete("...")] + class Program : IInterface + { + public static List<int> JustDoIt(int count) + { + Console.WriteLine($"Hello {Name}!"); + return new List<int>(new int[] { 1, 2, 3 }) + } + } +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.css b/swh/web/tests/resources/contents/code/extensions/test.css new file mode 100644 index 00000000..ede96c37 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.css @@ -0,0 +1,15 @@ +@font-face { + font-family: Chunkfive; src: url('Chunkfive.otf'); +} + +body, .usertext { + color: #F0F0F0; background: #600; + font-family: Chunkfive, sans; +} + +@import url(print.css); +@media print { + a[href^=http]::after { + content: attr(href) + } +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.d b/swh/web/tests/resources/contents/code/extensions/test.d new file mode 100644 index 00000000..ee9ae84e --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.d @@ -0,0 +1,44 @@ +#!/usr/bin/rdmd +// Computes average line length for standard input. +import std.stdio; + +/+ + this is a /+ nesting +/ comment ++/ + +enum COMPILED_ON = __TIMESTAMP__; // special token + +enum character = '©'; +enum copy_valid = '©'; +enum backslash_escaped = '\\'; + +// string literals +enum str = `hello "world"!`; +enum multiline = r"lorem +ipsum +dolor"; // wysiwyg string, no escapes here allowed +enum multiline2 = "sit +amet +\"adipiscing\" +elit."; +enum hex = x"66 6f 6f"; // same as "foo" + +#line 5 + +// float literals +enum f = [3.14f, .1, 1., 1e100, 0xc0de.01p+100]; + +static if (something == true) { + import std.algorithm; +} + +void main() pure nothrow @safe { + ulong lines = 0; + double sumLength = 0; + foreach (line; stdin.byLine()) { + ++lines; + sumLength += line.length; + } + writeln("Average line length: ", + lines ? sumLength / lines : 0); +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.dart b/swh/web/tests/resources/contents/code/extensions/test.dart new file mode 100644 index 00000000..a49b8e05 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.dart @@ -0,0 +1,37 @@ +library app; +import 'dart:html'; + +part 'app2.dart'; + +/** + * Class description and [link](http://dartlang.org/). + */ +@Awesome('it works!') +class SomeClass<S extends Iterable> extends BaseClass<S> implements Comparable { + factory SomeClass(num param); + SomeClass._internal(int q) : super() { + assert(q != 1); + double z = 0.0; + } + + /// **Sum** function + int sum(int a, int b) => a + b; + + ElementList els() => querySelectorAll('.dart'); +} + +String str = ' (${'parameter' + 'zxc'})'; +String str = " (${true ? 2 + 2 / 2 : null})"; +String str = " ($variable)"; +String str = r'\nraw\'; +String str = r"\nraw\"; +var str = ''' +Something ${2+3} +'''; +var str = r""" +Something ${2+3} +"""; + +checkVersion() async { + var version = await lookUpVersion(); +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.dcl b/swh/web/tests/resources/contents/code/extensions/test.dcl new file mode 100644 index 00000000..293b37ac --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.dcl @@ -0,0 +1,30 @@ +module fsieve + +import StdClass; // RWS +import StdInt, StdReal + +NrOfPrimes :== 3000 + +primes :: [Int] +primes = pr where pr = [5 : sieve 7 4 pr] + +sieve :: Int !Int [Int] -> [Int] +sieve g i prs +| isPrime prs g (toInt (sqrt (toReal g))) = [g : sieve` g i prs] +| otherwise = sieve (g + i) (6 - i) prs + +sieve` :: Int Int [Int] -> [Int] +sieve` g i prs = sieve (g + i) (6 - i) prs + +isPrime :: [Int] !Int Int -> Bool +isPrime [f:r] pr bd +| f>bd = True +| pr rem f==0 = False +| otherwise = isPrime r pr bd + +select :: [x] Int -> x +select [f:r] 1 = f +select [f:r] n = select r (n - 1) + +Start :: Int +Start = select [2, 3 : primes] NrOfPrimes \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.dfm b/swh/web/tests/resources/contents/code/extensions/test.dfm new file mode 100644 index 00000000..04028560 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.dfm @@ -0,0 +1,30 @@ +TList = Class(TObject) +Private + Some: String; +Public + Procedure Inside; // Suxx +End;{TList} + +Procedure CopyFile(InFileName, var OutFileName: String); +Const + BufSize = 4096; (* Huh? *) +Var + InFile, OutFile: TStream; + Buffer: Array[1..BufSize] Of Byte; + ReadBufSize: Integer; +Begin + InFile := Nil; + OutFile := Nil; + Try + InFile := TFileStream.Create(InFileName, fmOpenRead); + OutFile := TFileStream.Create(OutFileName, fmCreate); + Repeat + ReadBufSize := InFile.Read(Buffer, BufSize); + OutFile.Write(Buffer, ReadBufSize); + Until ReadBufSize<>BufSize; + Log('File ''' + InFileName + ''' copied'#13#10); + Finally + InFile.Free; + OutFile.Free; + End;{Try} +End;{CopyFile} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.diff b/swh/web/tests/resources/contents/code/extensions/test.diff new file mode 100644 index 00000000..4f4c04fe --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.diff @@ -0,0 +1,30 @@ +Index: languages/ini.js +=================================================================== +--- languages/ini.js (revision 199) ++++ languages/ini.js (revision 200) +@@ -1,8 +1,7 @@ + hljs.LANGUAGES.ini = + { + case_insensitive: true, +- defaultMode: +- { ++ defaultMode: { + contains: ['comment', 'title', 'setting'], + illegal: '[^\\s]' + }, + +*** /path/to/original timestamp +--- /path/to/new timestamp +*************** +*** 1,3 **** +--- 1,9 ---- ++ This is an important ++ notice! It should ++ therefore be located at ++ the beginning of this ++ document! + +! compress the size of the +! changes. + + It is important to spell diff --git a/swh/web/tests/resources/contents/code/extensions/test.do b/swh/web/tests/resources/contents/code/extensions/test.do new file mode 100644 index 00000000..63959e90 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.do @@ -0,0 +1,40 @@ +program define gr_log +version 6.0 + +local or = `2' +local xunits = `3' +local b1 = ln(`or') + +* make summary of logistic data from equation +set obs `xunits' +generate pgty = 1 - 1/(1 + exp(score)) +/** + * Comment 1 +*/ +reg y x +* Comment 2 +reg y2 x //comment 3 +This is a `loc' $glob ${glob2} +This is a `"string " "' "string`1'two${hi}" bad `"string " "' good `"string " "' + +//Limit to just the project ados +cap adopath - SITE +cap adopath - PLUS +/*cap adopath - PERSONAL +cap adopath - OLDPLACE*/ +adopath ++ "${dir_base}/code/ado/" +A string `"Wow"'. `""one" "two""' +A `local' em`b'ed +a global ${dir_base} $dir_base em${b}ed + +forval i=1/4{ + if `i'==2{ + cap reg y x1, robust + local x = ln(4) + local x =ln(4) + local ln = ln + } +} + +* add mlibs in the new adopath to the index +mata: mata mlib index \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.dts b/swh/web/tests/resources/contents/code/extensions/test.dts new file mode 100644 index 00000000..b65681ed --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.dts @@ -0,0 +1,34 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun4i-a10", "allwinner,sun7i-a20", "allwinner,sun8i-h3", "allwinner,sun50i-a64", "allwinner,sun50i-h5"; + + fragment@0 { + target = <&pio>; + __overlay__ { + apds9960_pin_irq: apds9960_pin_irq { + pins = "PA10"; + function = "irq"; + bias-pull-up; + }; + }; + }; + + fragment@1 { + target = <&i2c0>; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + apds9960@39 { + compatible = "avago,apds9960"; + reg = <0x39>; + pinctrl-names = "default"; + pinctrl-0 = <&apds9960_pin_irq>; + interrupt-parent = <&pio>; + interrupts = <0 10 2>; /* PA10 IRQ_TYPE_EDGE_FALLING */ + status = "okay"; + }; + }; + }; +}; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.dust b/swh/web/tests/resources/contents/code/extensions/test.dust new file mode 100644 index 00000000..11bc7eb0 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.dust @@ -0,0 +1,7 @@ +<h3>Hours</h3> + +<ul> + {#users} + <li {hello}>{firstName}</li>{~n} + {/users} +</ul> diff --git a/swh/web/tests/resources/contents/code/extensions/test.ebnf b/swh/web/tests/resources/contents/code/extensions/test.ebnf new file mode 100644 index 00000000..a51dc648 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ebnf @@ -0,0 +1,12 @@ +(* line comment *) + +rule = [optional] , symbol , { letters } , ( digit | symbol ) ; + +optional = ? something unnecessary ? ; (* trailing comment *) + +symbol = '!' | '@' | '#' | '$' | '%' | '&' | '*' ; +digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; +letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" + | "H" | "I" | "J" | "K" | "L" | "M" | "N" + | "O" | "P" | "Q" | "R" | "S" | "T" | "U" + | "V" | "W" | "X" | "Y" | "Z" ; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.elm b/swh/web/tests/resources/contents/code/extensions/test.elm new file mode 100644 index 00000000..f2380e5a --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.elm @@ -0,0 +1,18 @@ +import Html exposing (div, button, text) +import Html.App exposing (beginnerProgram) +import Html.Events exposing (onClick) + +type Msg + = Increment + +main = + beginnerProgram + { model = 0, view = view + , update = \Increment model -> model + 1 } + +view model = + div [] [ div [] [ text (toString model) ] + , button [ onClick Increment ] [ text "+" ] ] + +chars = + String.cons 'C' <| String.cons 'h' <| "ars" diff --git a/swh/web/tests/resources/contents/code/extensions/test.ep b/swh/web/tests/resources/contents/code/extensions/test.ep new file mode 100644 index 00000000..2cd9426f --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ep @@ -0,0 +1,20 @@ +%layout 'bootstrap'; +% title "Import your subs"; +%= form_for '/settings/import' => (method => 'post', enctype => 'multipart/form-data') => begin + %= file_field 'opmlfile' => multiple => 'true' + %= submit_button 'Import', 'class' => 'btn' +% end +<div> +% if ($subs) { +<dl> +% for my $item (@$subs) { +% my ($dir, $align) = ($item->{rtl}) ? ('rtl', 'right') : ('ltr', 'left'); +<dt align="<%= $align %>"><a href="<%= $item->{'xmlUrl'} %>"><i class="icon-rss"></i> rss</a> +<a dir="<%= $dir %>" href="<%= $item->{htmlUrl} %>"><%== $item->{title} %></a> +</dt> +<dd><b>Categories</b> +%= join q{, }, sort @{ $item->{categories} || [] }; +</dd> +</dl> +% } +</div> diff --git a/swh/web/tests/resources/contents/code/extensions/test.erb b/swh/web/tests/resources/contents/code/extensions/test.erb new file mode 100644 index 00000000..f7ea6203 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.erb @@ -0,0 +1,10 @@ +<%# this is a comment %> + +<% @posts.each do |post| %> + <p><%= link_to post.title, post %></p> +<% end %> + +<%- available_things = things.select(&:available?) -%> +<%%- x = 1 + 2 -%%> +<%% value = 'real string #{@value}' %%> +<%%= available_things.inspect %%> diff --git a/swh/web/tests/resources/contents/code/extensions/test.erl b/swh/web/tests/resources/contents/code/extensions/test.erl new file mode 100644 index 00000000..528e0644 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.erl @@ -0,0 +1,60 @@ +-module(ssh_cli). + +-behaviour(ssh_channel). + +-include("ssh.hrl"). +%% backwards compatibility +-export([listen/1, listen/2, listen/3, listen/4, stop/1]). + +if L =/= [] -> % If L is not empty + sum(L) / count(L); +true -> + error +end. + +%% state +-record(state, { + cm, + channel + }). + +-spec foo(integer()) -> integer(). +foo(X) -> 1 + X. + +test(Foo)->Foo. + +init([Shell, Exec]) -> + {ok, #state{shell = Shell, exec = Exec}}; +init([Shell]) -> + false = not true, + io:format("Hello, \"~p!~n", [atom_to_list('World')]), + {ok, #state{shell = Shell}}. + +concat([Single]) -> Single; +concat(RList) -> + EpsilonFree = lists:filter( + fun (Element) -> + case Element of + epsilon -> false; + _ -> true + end + end, + RList), + case EpsilonFree of + [Single] -> Single; + Other -> {concat, Other} + end. + +union_dot_union({union, _}=U1, {union, _}=U2) -> + union(lists:flatten( + lists:map( + fun (X1) -> + lists:map( + fun (X2) -> + concat([X1, X2]) + end, + union_to_list(U2) + ) + end, + union_to_list(U1) + ))). diff --git a/swh/web/tests/resources/contents/code/extensions/test.ex b/swh/web/tests/resources/contents/code/extensions/test.ex new file mode 100644 index 00000000..3bd83e83 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ex @@ -0,0 +1,72 @@ +defmodule Display do + use GenServer + + alias IO.ANSI + alias Display.{ProgressBar, Intro, Failure, Notifications} + + def start_link do + GenServer.start_link(__MODULE__, %{clear_screen: true}, name: __MODULE__) + end + + def init(args) do + {:ok, args} + end + + def disable_clear do + GenServer.cast(__MODULE__, :disable_clear) + end + + def handle_cast(:disable_clear, state) do + {:noreply, %{state | clear_screen: false}} + end + + def handle_cast(:clear_screen, state = %{clear_screen: true}) do + IO.puts(ANSI.clear()) + IO.puts(ANSI.home()) + + {:noreply, state} + end + + def handle_cast(:clear_screen, state) do + {:noreply, state} + end + + def invalid_koan(koan, modules) do + Notifications.invalid_koan(koan, modules) + |> IO.puts() + end + + def show_failure(failure, module, name) do + format(failure, module, name) + |> IO.puts() + end + + def show_compile_error(error) do + Failure.show_compile_error(error) + |> IO.puts() + end + + def congratulate do + Notifications.congratulate() + |> IO.puts() + end + + def clear_screen do + GenServer.cast(__MODULE__, :clear_screen) + end + + defp format(failure, module, name) do + """ + #{Intro.intro(module, Tracker.visited())} + Now meditate upon #{format_module(module)} + #{ProgressBar.progress_bar(Tracker.summarize())} + ---------------------------------------- + #{name} + #{Failure.format_failure(failure)} + """ + end + + defp format_module(module) do + Module.split(module) |> List.last() + end +end diff --git a/swh/web/tests/resources/contents/code/extensions/test.f90 b/swh/web/tests/resources/contents/code/extensions/test.f90 new file mode 100644 index 00000000..1d41b40b --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.f90 @@ -0,0 +1,22 @@ +subroutine test_sub(k) + implicit none + + !=============================== + ! This is a test subroutine + !=============================== + + integer, intent(in) :: k + double precision, allocatable :: a(:) + integer, parameter :: nmax=10 + integer :: i + + allocate (a(nmax)) + + do i=1,nmax + a(i) = dble(i)*5.d0 + enddo + + print *, 'Hello world' + write (*,*) a(:) + +end subroutine test_sub diff --git a/swh/web/tests/resources/contents/code/extensions/test.feature b/swh/web/tests/resources/contents/code/extensions/test.feature new file mode 100644 index 00000000..52981fd1 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.feature @@ -0,0 +1,25 @@ +# language: en +Feature: Addition + In order to avoid silly mistakes + As a math idiot + I want to be told the sum of two numbers + + @this_is_a_tag + Scenario Outline: Add two numbers + * I have a calculator + Given I have entered <input_1> into the calculator + And I have entered <input_2> into the calculator + When I press <button> + Then the result should be <output> on the screen + And I have a string like + """ + Here is + some + multiline text + """ + + Examples: + | input_1 | input_2 | button | output | + | 20 | 30 | add | 50 | + | 2 | 5 | add | 7 | + | 0 | 40 | add | 40 | diff --git a/swh/web/tests/resources/contents/code/extensions/test.flix b/swh/web/tests/resources/contents/code/extensions/test.flix new file mode 100644 index 00000000..5f7ea4ce --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.flix @@ -0,0 +1,49 @@ +/** + * An example of Flix for syntax highlighting. + */ + +// Here is a namespace. +namespace a.b.c { + + // Here are some literals. + def b: Bool = true + def c: Char = 'a' + def f: Float = 1.23 + def i: Int = 42 + def s: Str = "string" + + // Here are some relations. + rel LitStm(r: Str, c: Int) + rel AddStm(r: Str, x: Str, y: Str) + rel DivStm(r: Str, x: Str, y: Str) + + // Here is a lattice. + lat LocalVar(k: Str, v: Constant) + + // Here is an index. + index LitStm{{r}, {r, c}} + + // Here is an enum. + enum Constant { + case Top, + + case Cst(Int), + + case Bot + } + + // Here is a function. + def leq(e1: Constant, e2: Constant): Bool = match (e1, e2) with { + case (Constant.Bot, _) => true + case (Constant.Cst(n1), Constant.Cst(n2)) => n1 == n2 + case (_, Constant.Top) => true + case _ => false + } + + // Here are some rules. + LocalVar(r, alpha(c)) :- LitStm(r, c). + + LocalVar(r, sum(v1, v2)) :- AddStm(r, x, y), + LocalVar(x, v1), + LocalVar(y, v2). +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.fs b/swh/web/tests/resources/contents/code/extensions/test.fs new file mode 100644 index 00000000..aa3510a8 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.fs @@ -0,0 +1,48 @@ +open System + +// Single line comment... +(* + This is a + multiline comment. +*) +let checkList alist = + match alist with + | [] -> 0 + | [a] -> 1 + | [a; b] -> 2 + | [a; b; c] -> 3 + | _ -> failwith "List is too big!" + + +let text = "Some text..." +let text2 = @"A ""verbatim"" string..." +let catalog = """ +Some "long" string... +""" + +let rec fib x = if x <= 2 then 1 else fib(x-1) + fib(x-2) + +let fibs = + Async.Parallel [ for i in 0..40 -> async { return fib(i) } ] + |> Async.RunSynchronously + +type Sprocket(gears) = + member this.Gears : int = gears + +[<AbstractClass>] +type Animal = + abstract Speak : unit -> unit + +type Widget = + | RedWidget + | GreenWidget + +type Point = {X: float; Y: float;} + +[<Measure>] +type s +let minutte = 60<s> + +type DefaultMailbox<'a>() = + let mutable inbox = ConcurrentQueue<'a>() + let awaitMsg = new AutoResetEvent(false) \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.gcode b/swh/web/tests/resources/contents/code/extensions/test.gcode new file mode 100644 index 00000000..5f47bca3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.gcode @@ -0,0 +1,31 @@ +O003 (DIAMOND SQUARE) +N2 G54 G90 G49 G80 +N3 M6 T1 (1.ENDMILL) +N4 M3 S1800 +N5 G0 X-.6 Y2.050 +N6 G43 H1 Z.1 +N7 G1 Z-.3 F50. +N8 G41 D1 Y1.45 +N9 G1 X0 F20. +N10 G2 J-1.45 +(CUTTER COMP CANCEL) +N11 G1 Z-.2 F50. +N12 Y-.990 +N13 G40 +N14 G0 X-.6 Y1.590 +N15 G0 Z.1 +N16 M5 G49 G28 G91 Z0 +N17 CALL O9456 +N18 #500=0.004 +N19 #503=[#500+#501] +N20 VC45=0.0006 +VS4=0.0007 +N21 G90 G10 L20 P3 X5.Y4. Z6.567 +N22 G0 X5000 +N23 IF [#1 LT 0.370] GOTO 49 +N24 X-0.678 Y+.990 +N25 G84.3 X-0.1 +N26 #4=#5*COS[45] +N27 #4=#5*SIN[45] +N28 VZOFZ=652.9658 +% \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.glsl b/swh/web/tests/resources/contents/code/extensions/test.glsl new file mode 100644 index 00000000..ddaf2464 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.glsl @@ -0,0 +1,37 @@ +// vertex shader +#version 150 +in vec2 in_Position; +in vec3 in_Color; + +out vec3 ex_Color; +void main(void) { + gl_Position = vec4(in_Position.x, in_Position.y, 0.0, 1.0); + ex_Color = in_Color; +} + + +// geometry shader +#version 150 + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +void main() { + for(int i = 0; i < gl_in.length(); i++) { + gl_Position = gl_in[i].gl_Position; + EmitVertex(); + } + EndPrimitive(); +} + + +// fragment shader +#version 150 +precision highp float; + +in vec3 ex_Color; +out vec4 gl_FragColor; + +void main(void) { + gl_FragColor = vec4(ex_Color, 1.0); +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.gml b/swh/web/tests/resources/contents/code/extensions/test.gml new file mode 100644 index 00000000..9528595c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.gml @@ -0,0 +1,22 @@ +/// @description Collision code +// standard collision handling + +// Horizontal collisions +if(place_meeting(x+hspd, y, obj_wall)) { + while(!place_meeting(x+sign(hspd), y, obj_wall)) { + x += sign(hspd); + } + hspd = 0; +} +x += hspd; + +// Vertical collisions +if(place_meeting(x, y+vspd, collide_obj)) { + while(!place_meeting(x, y+sign(vspd), collide_obj)) { + y += sign(vspd); + } + vspd = 0; +} +y += vspd; + +show_debug_message("This is a test"); \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.gms b/swh/web/tests/resources/contents/code/extensions/test.gms new file mode 100644 index 00000000..3651f9b2 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.gms @@ -0,0 +1,31 @@ +SETS + I canning plants / SEATTLE, SAN-DIEGO / + J markets / NEW-YORK, CHICAGO, TOPEKA / ; +PARAMETERS + A(I) capacity of plant i in cases + / SEATTLE 350 + SAN-DIEGO 600 / + B(J) demand at market j in cases + / NEW-YORK 325 + CHICAGO 300 + TOPEKA 275 / ; +TABLE D(I,J) distance in thousands of miles + NEW-YORK CHICAGO TOPEKA + SEATTLE 2.5 1.7 1.8 + SAN-DIEGO 2.5 1.8 1.4 ; +SCALAR F freight in dollars per case per thousand miles /90/ ; +PARAMETER C(I,J) transport cost in thousands of dollars per case ; + C(I,J) = F * D(I,J) / 1000 ; +VARIABLES + X(I,J) shipment quantities in cases + Z total transportation costs in thousands of dollars ; +POSITIVE VARIABLE X ; +EQUATIONS + COST define objective function + SUPPLY(I) observe supply limit at plant i + DEMAND(J) satisfy demand at market j ; +COST .. Z =E= SUM((I,J), C(I,J)*X(I,J)) ; +SUPPLY(I) .. SUM(J, X(I,J)) =L= A(I) ; +DEMAND(J) .. SUM(I, X(I,J)) =G= B(J) ; +MODEL TRANSPORT /ALL/ ; +SOLVE TRANSPORT USING LP MINIMIZING Z ; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.go b/swh/web/tests/resources/contents/code/extensions/test.go new file mode 100644 index 00000000..34c584f8 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.go @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + ch := make(chan float64) + ch <- 1.0e10 // magic number + x, ok := <- ch + defer fmt.Println(`exitting now\`) + go println(len("hello world!")) + return +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.golo b/swh/web/tests/resources/contents/code/extensions/test.golo new file mode 100644 index 00000000..0d87f669 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.golo @@ -0,0 +1,15 @@ +module hello + +function dyno = -> DynamicObject() + +struct human = { name } + +@annotated +function main = |args| { + let a = 1 + var b = 2 + + println("hello") + + let john = human("John Doe") +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.gradle b/swh/web/tests/resources/contents/code/extensions/test.gradle new file mode 100644 index 00000000..643dcbcf --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.gradle @@ -0,0 +1,61 @@ +apply plugin: 'android' + +android { + compileSdkVersion 19 + buildToolsVersion "19.1" + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 19 + versionCode 5 + versionName "0.4.4" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + signingConfigs { + release + } + buildTypes { + release { + // runProguard true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + signingConfig signingConfigs.release + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + + compile 'com.example:example-lib:1.0.0' +} + + +def propFile = file('../signing.properties') +if( propFile.canRead() ) { + def Properties p = new Properties() + p.load(new FileInputStream(propFile)) + + if( p!=null + && p.containsKey("STORE_FILE") + && p.containsKey('STORE_PASSWORD') + && p.containsKey('KEY_ALIAS') + && p.containsKey('KEY_PASSWORD') + ) { + println "RELEASE_BUILD: Signing..." + + android.signingConfigs.release.storeFile = file( p['STORE_FILE'] ) + android.signingConfigs.release.storePassword = p['STORE_PASSWORD'] + android.signingConfigs.release.keyAlias = p['KEY_ALIAS'] + android.signingConfigs.release.keyPassword = p['KEY_PASSWORD'] + } else { + println "RELEASE_BUILD: Required properties in signing.properties are missing" + android.buildTypes.release.signingConfig = null + } +} else { + println "RELEASE_BUILD: signing.properties not found" + android.buildTypes.release.signingProperties = null +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.groovy b/swh/web/tests/resources/contents/code/extensions/test.groovy new file mode 100644 index 00000000..0fb36ab5 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.groovy @@ -0,0 +1,56 @@ +#!/usr/bin/env groovy +package model + +import groovy.transform.CompileStatic +import java.util.List as MyList + +trait Distributable { + void distribute(String version) {} +} + +@CompileStatic +class Distribution implements Distributable { + double number = 1234.234 / 567 + def otherNumber = 3 / 4 + boolean archivable = condition ?: true + def ternary = a ? b : c + String name = "Guillaume" + Closure description = null + List<DownloadPackage> packages = [] + String regex = ~/.*foo.*/ + String multi = ''' + multi line string + ''' + """ + now with double quotes and ${gstring} + """ + $/ + even with dollar slashy strings + /$ + + /** + * description method + * @param cl the closure + */ + void description(Closure cl) { this.description = cl } + + void version(String name, Closure versionSpec) { + def closure = { println "hi" } as Runnable + + MyList ml = [1, 2, [a: 1, b:2,c :3]] + for (ch in "name") {} + + // single line comment + DownloadPackage pkg = new DownloadPackage(version: name) + + check that: true + + label: + def clone = versionSpec.rehydrate(pkg, pkg, pkg) + /* + now clone() in a multiline comment + */ + clone() + packages.add(pkg) + + assert 4 / 2 == 2 + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.gss b/swh/web/tests/resources/contents/code/extensions/test.gss new file mode 100644 index 00000000..3eb4f0b8 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.gss @@ -0,0 +1,28 @@ +// This is a test +#include pv.sdf + +proc (1) = calc(local__row, fin); + if local__row; + nr = local__row; + else; + k = colsf(fin); + nr = floor(minc(maxbytes/(k*8*3.5)|maxvec/(k+1))); + endif; + retp(nr); +endp; + +s = "{% test string %}"; + +fn twopi=pi*2; + +/* Takes in multiple numbers. + Output sum */ +keyword add(str); + local tok,sum; + sum = 0; + do until str $== ""; + { tok, str } = token(str); + sum = sum + stof(tok); + endo; + print "Sum is: " sum; +endp; diff --git a/swh/web/tests/resources/contents/code/extensions/test.haml b/swh/web/tests/resources/contents/code/extensions/test.haml new file mode 100644 index 00000000..47121170 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.haml @@ -0,0 +1,14 @@ +!!! XML +%html + %body + %h1.jumbo{:id=>"a", :style=>'font-weight: normal', :title=>title} highlight.js + /html comment + -# ignore this line + %ul(style='margin: 0') + -items.each do |i| + %i= i + = variable + =variable2 + ~ variable3 + ~variable4 + The current year is #{DataTime.now.year}. \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.hbs b/swh/web/tests/resources/contents/code/extensions/test.hbs new file mode 100644 index 00000000..ca9be828 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.hbs @@ -0,0 +1,6 @@ +<div class="entry"> + {{!-- only show if author exists --}} + {{#if author}} + <h1>{{firstName}} {{lastName}}</h1> + {{/if}} +</div> diff --git a/swh/web/tests/resources/contents/code/extensions/test.hs b/swh/web/tests/resources/contents/code/extensions/test.hs new file mode 100644 index 00000000..530f9439 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.hs @@ -0,0 +1,38 @@ +{-# LANGUAGE TypeSynonymInstances #-} +module Network.UDP +( DataPacket(..) +, openBoundUDPPort +, openListeningUDPPort +, pingUDPPort +, sendUDPPacketTo +, recvUDPPacket +, recvUDPPacketFrom +) where + +import qualified Data.ByteString as Strict (ByteString, concat, singleton) +import qualified Data.ByteString.Lazy as Lazy (ByteString, toChunks, fromChunks) +import Data.ByteString.Char8 (pack, unpack) +import Network.Socket hiding (sendTo, recv, recvFrom) +import Network.Socket.ByteString (sendTo, recv, recvFrom) + +-- Type class for converting StringLike types to and from strict ByteStrings +class DataPacket a where + toStrictBS :: a -> Strict.ByteString + fromStrictBS :: Strict.ByteString -> a + +instance DataPacket Strict.ByteString where + toStrictBS = id + {-# INLINE toStrictBS #-} + fromStrictBS = id + {-# INLINE fromStrictBS #-} + +openBoundUDPPort :: String -> Int -> IO Socket +openBoundUDPPort uri port = do + s <- getUDPSocket + bindAddr <- inet_addr uri + let a = SockAddrInet (toEnum port) bindAddr + bindSocket s a + return s + +pingUDPPort :: Socket -> SockAddr -> IO () +pingUDPPort s a = sendTo s (Strict.singleton 0) a >> return () \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.hsp b/swh/web/tests/resources/contents/code/extensions/test.hsp new file mode 100644 index 00000000..eab71ee0 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.hsp @@ -0,0 +1,23 @@ +#include "foo.hsp" + + // line comment + message = "Hello, World!" + message2 = {"Multi + line + string"} + num = 0 + mes message + + input num : button "sqrt", *label + stop + +*label + /* + block comment + */ + if(num >= 0) { + dialog "sqrt(" + num + ") = " + sqrt(num) + } else { + dialog "error", 1 + } + stop \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.html b/swh/web/tests/resources/contents/code/extensions/test.html new file mode 100644 index 00000000..82bc7f16 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<title>Title</title> + +<style>body {width: 500px;}</style> + +<script type="application/javascript"> + function $init() {return true;} +</script> + +<body> + <p checked class="title" id='title'>Title</p> + <!-- here goes the rest of the page --> +</body> diff --git a/swh/web/tests/resources/contents/code/extensions/test.hx b/swh/web/tests/resources/contents/code/extensions/test.hx new file mode 100644 index 00000000..73d06ebc --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.hx @@ -0,0 +1,142 @@ +package my.package; + +#if js +import js.Browser; +#elseif sys +import Sys; +#else +import Date; +#end + +import Lambda; +using Main.IntExtender; + +extern class Math { + static var PI(default,null) : Float; + static function floor(v:Float):Int; +} + +/** + * Abstract forwarding + */ +abstract MyAbstract(Int) from Int to Int { + inline function new(i:Int) { + this = i; + } + + @:op(A * B) + public function multiply(rhs:MyAbstract) { + return this * rhs; + } +} + +// an enum +enum Color { + Red; + Green; + Blue; + Rgb(r:Int, g:Int, b:Int); +} + +@:generic +class Gen<T> { + var v:T; + public function new(v:T) { + this.v = v; + } + + public var x(get, set):T; + + private inline function get_x():T + return v; + + private inline function set_x(x:T):T + return v = x; +} + +class Main extends BaseClass implements SomeFunctionality { + var callback:Void->Void = null; + var myArray:Array<Float> = new Array<Float>(); + var arr = [4,8,0,3,9,1,5,2,6,7]; + + public function new(x) { + super(x); + } + + public static function main() { + trace('What\'s up?'); + trace('Hi, ${name}!'); + + // switch statements! + var c:Color = Color.Green; + var x:Int = switch(c) { + case Red: 0; + case Green: 1; + case Blue: 2; + case Rgb(r, g, b): 3; + case _: -1; + } + + for(i in 0...3) { + trace(i); + continue; + break; + } + + do { + trace("Hey-o!"); + } while(false); + + var done:Bool = false; + while(!done) { + done = true; + } + + var H:Int = cast new MyAbstract(42); + var h:Int = cast(new MyAbstract(31), Int); + + try { + throw "error"; + } + catch(err:String) { + trace(err); + } + + var map = new haxe.ds.IntMap<String>(); + var f = map.set.bind(_, "12"); + } + + function nothing():Void + trace("nothing!"); + + private inline function func(a:Int, b:Float, ?c:String, d:Bool=false):Dynamic { + return { + x: 0, + y: true, + z: false, + a: 1.53, + b: 5e10, + c: -12, + h: null + }; + } + + + override function quicksort( lo : Int, hi : Int ) : Void { + var i = lo; + var j = hi; + var buf = arr; + var p = buf[(lo+hi)>>1]; + while( i <= j ) { + while( arr[i] > p ) i++; + while( arr[j] < p ) j--; + if( i <= j ) { + var t = buf[i]; + buf[i++] = buf[j]; + buf[j--] = t; + } + } + if( lo < j ) quicksort( lo, j ); + if( i < hi ) quicksort( i, hi ); + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.hy b/swh/web/tests/resources/contents/code/extensions/test.hy new file mode 100644 index 00000000..12490ae4 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.hy @@ -0,0 +1,37 @@ +#!/usr/bin/env hy + +(import os.path) + +(import hy.compiler) +(import hy.core) + + +;; absolute path for Hy core +(setv *core-path* (os.path.dirname hy.core.--file--)) + + +(defn collect-macros [collected-names opened-file] + (while True + (try + (let [data (read opened-file)] + (if (and (in (first data) + '(defmacro defmacro/g! defn)) + (not (.startswith (second data) "_"))) + (.add collected-names (second data)))) + (except [e EOFError] (break))))) + + +(defmacro core-file [filename] + `(open (os.path.join *core-path* ~filename))) + + +(defmacro contrib-file [filename] + `(open (os.path.join *core-path* ".." "contrib" ~filename))) + + +(defn collect-core-names [] + (doto (set) + (.update hy.core.language.*exports*) + (.update hy.core.shadow.*exports*) + (collect-macros (core-file "macros.hy")) + (collect-macros (core-file "bootstrap.hy")))) \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ini b/swh/web/tests/resources/contents/code/extensions/test.ini new file mode 100644 index 00000000..03a5c297 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ini @@ -0,0 +1,12 @@ +; boilerplate +[package] +name = "some_name" +authors = ["Author"] +description = "This is \ +a description" + +[[lib]] +name = ${NAME} +default = True +auto = no +counter = 1_000 diff --git a/swh/web/tests/resources/contents/code/extensions/test.ino b/swh/web/tests/resources/contents/code/extensions/test.ino new file mode 100644 index 00000000..798fe04a --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ino @@ -0,0 +1,24 @@ +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + + This example code is in the public domain. + */ + +// Pin 13 has an LED connected on most Arduino boards. +// give it a name: +int led = 13; + +// the setup routine runs once when you press reset: +void setup() { + // initialize the digital pin as an output. + pinMode(led, OUTPUT); +} + +// the loop routine runs over and over again forever: +void loop() { + digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(led, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.java b/swh/web/tests/resources/contents/code/extensions/test.java new file mode 100644 index 00000000..a32749d2 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.java @@ -0,0 +1,16 @@ +/** + * @author John Smith <john.smith@example.com> +*/ +package l2f.gameserver.model; + +public abstract class L2Char extends L2Object { + public static final Short ERROR = 0x0001; + + public void moveTo(int x, int y, int z) { + _ai = null; + log("Should not be called"); + if (1 > 5) { // wtf!? + return; + } + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.jl b/swh/web/tests/resources/contents/code/extensions/test.jl new file mode 100644 index 00000000..ef3ccf6f --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.jl @@ -0,0 +1,104 @@ +### Types + +# Old-style definitions + +immutable Point{T<:AbstractFloat} + index::Int + x::T + y::T +end + +abstract A + +type B <: A end + +typealias P Point{Float16} + +# New-style definitions + +struct Plus + f::typeof(+) +end + +mutable struct Mut + mutable::A # mutable should not be highlighted (not followed by struct) + primitive::B # primitive should not be highlighted (not followed by type) +end + +primitive type Prim 8 end + +abstract type Abstr end + +### Modules + +module M + +using X +import Y +importall Z + +export a, b, c + +end # module + +baremodule Bare +end + +### New in 0.6 + +# where, infix isa, UnionAll +function F{T}(x::T) where T + for i in x + i isa UnionAll && return + end +end + +### Miscellaneous + +#= +Multi +Line +Comment +=# +function method0(x, y::Int; version::VersionNumber=v"0.1.2") + """ + Triple + Quoted + String + """ + + @assert π > e + + s = 1.2 + 変数 = "variable" + + if s * 100_000 ≥ 5.2e+10 && true || x === nothing + s = 1. + .5im + elseif 1 ∈ [1, 2, 3] + println("s is $s and 変数 is $変数") + else + x = [1 2 3; 4 5 6] + @show x' + end + + local var = rand(10) + global g = 44 + var[1:5] + var[5:end-1] + var[end] + + opt = "-la" + run(`ls $opt`) + + try + ccall(:lib, (Ptr{Void},), Ref{C_NULL}) + catch + throw(ArgumentError("wat")) + finally + warn("god save the queen") + end + + '\u2200' != 'T' + + return 5s / 2 +end \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.js b/swh/web/tests/resources/contents/code/extensions/test.js new file mode 100644 index 00000000..cf994d2d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.js @@ -0,0 +1,21 @@ +function $initHighlight(block, cls) { + try { + if (cls.search(/\bno\-highlight\b/) != -1) + return process(block, true, 0x0F) + + ` class="${cls}"`; + } catch (e) { + /* handle exception */ + } + for (var i = 0 / 2; i < classes.length; i++) { + if (checkCondition(classes[i]) === undefined) + console.log('undefined'); + } + + return ( + <div> + <web-component>{block}</web-component> + </div> + ) +} + +export $initHighlight; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.json b/swh/web/tests/resources/contents/code/extensions/test.json new file mode 100644 index 00000000..9710b228 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.json @@ -0,0 +1,12 @@ +[ + { + "title": "apples", + "count": [12000, 20000], + "description": {"text": "...", "sensitive": false} + }, + { + "title": "oranges", + "count": [17500, null], + "description": {"text": "...", "sensitive": false} + } +] diff --git a/swh/web/tests/resources/contents/code/extensions/test.kt b/swh/web/tests/resources/contents/code/extensions/test.kt new file mode 100644 index 00000000..5360533a --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.kt @@ -0,0 +1,12 @@ +import kotlin.lang.test + +trait A { + fun x() +} + +fun xxx() : Int { + return 888 +} + +public fun main(args : Array<String>) { +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.lasso b/swh/web/tests/resources/contents/code/extensions/test.lasso new file mode 100644 index 00000000..87365981 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.lasso @@ -0,0 +1,48 @@ +<?LassoScript +/* Lasso 8 */ + local('query' = 'SELECT * FROM `'+var:'table'+'` WHERE `id` > 10 + ORDER BY `Name` LIMIT 30'); + Inline: -Username=$DBuser, -Password=$DBpass, -Database=$DBname, -sql=#query; + var("class1.name" = (found_count != 0 ? "subtotal" | "nonefound"), + "total_amount" = found_count || "No results"); + records; + output: "<tr>"loop_count"</tr>"; + /records; + /Inline; +?><div class="[$class1.name]">[$total_amount]</div> +<?lasso +/* Lasso 9 */ ?> +[noprocess] causes [delimiters] to be <?=skipped?> until the next [/noprocess] +[ + define strings.combine(value::string, ...other)::string => { + local(result = #value->append(#other->asString&trim)) + return set(#result, not #other, \givenBlock) + } + /**! descriptive text */ + define person => type { + parent entity + data name::string, protected nickname, birthdate :: date + data private ssn = null + private showAge() => frozen { return ..age } + protected fullName() => `"` + .nickname + `"` + .'name' + public ssnListed::boolean => .ssn() ? true | false + } + define person->name=(value) => { + .'name' = #value + return self->'name' + } + define bytes->+(rhs::bytes) => bytes(self)->append(#rhs)& +] <!-- an HTML comment <?=disables delimiters?> as well --> +[no_square_brackets] disables [square brackets] for the rest of the file +<?= + // query expression + with n in array((:-12, 0xABCD, 3.14159e14), (:NaN, -infinity, .57721)) + let swapped = pair(#n->\second, #n->first) + group #swapped by #n->first into t + let key = #t->key + order by #key + select pair(#key, #1) + do {^ + #n->upperCase + ^} +?> \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.lc b/swh/web/tests/resources/contents/code/extensions/test.lc new file mode 100644 index 00000000..aba35ea9 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.lc @@ -0,0 +1,30 @@ +<?rev + +global gControllerHandlers, gData +local sTest +put "blog,index" into gControllerHandlers + + +command blog + -- simple comment + put "Hello World!" into sTest + # ANOTHER COMMENT + put "form,url,asset" into tHelpers + rigLoadHelper tHelpers +end blog + +/*Hello +block comment!*/ + +function myFunction + if the secs > 2000000000 then + put "Welcome to the future!" + else + return "something" + end if +end myFunction + + +--| END OF blog.lc +--| Location: ./system/application/controllers/blog.lc +---------------------------------------------------------------------- \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ldif b/swh/web/tests/resources/contents/code/extensions/test.ldif new file mode 100644 index 00000000..7bf3cfea --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ldif @@ -0,0 +1,25 @@ +# Example LDAP user +dn: uid=user.0,ou=People,dc=example,dc=com +objectClass: top +objectClass: person +objectClass: organizationalPerson +objectClass: inetOrgPerson +givenName: Morris +sn: Day +cn: Morris Day +initials: MD +employeeNumber: 0 +uid: user.0 +mail: user.0@example.com +userPassword: password +telephoneNumber: +1 042 100 3866 +homePhone: +1 039 680 4135 +pager: +1 284 199 0966 +mobile: +1 793 707 0251 +street: 90280 Spruce Street +l: Minneapolis +st: MN +postalCode: 50401 +postalAddress: Morris Day$90280 Spruce Street$Minneapolis, MN 50401 +description: This is the description for Morris Day. + diff --git a/swh/web/tests/resources/contents/code/extensions/test.leaf b/swh/web/tests/resources/contents/code/extensions/test.leaf new file mode 100644 index 00000000..5c47e88d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.leaf @@ -0,0 +1,21 @@ +#empty(friends) { + Try adding some friends! +} ##loop(friends, "friend") { + <li> #(friend.name) </li> +} + +#someTag(parameter.list, goes, "here") { + This is an optional body here +} + +#index(friends, "0") { + Hello, #(self)! +} ##else() { + Nobody's there! +} + +#() + +#raw() { + <li> Hello </li> +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.less b/swh/web/tests/resources/contents/code/extensions/test.less new file mode 100644 index 00000000..ce100f7d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.less @@ -0,0 +1,27 @@ +@import "fruits"; + +@rhythm: 1.5em; + +@media screen and (min-resolution: 2dppx) { + body {font-size: 125%} +} + +section > .foo + #bar:hover [href*="less"] { + margin: @rhythm 0 0 @rhythm; + padding: calc(5% + 20px); + background: #f00ba7 url(http://placehold.alpha-centauri/42.png) no-repeat; + background-image: linear-gradient(-135deg, wheat, fuchsia) !important ; + background-blend-mode: multiply; +} + +@font-face { + font-family: /* ? */ 'Omega'; + src: url('../fonts/omega-webfont.woff?v=2.0.2'); +} + +.icon-baz::before { + display: inline-block; + font-family: "Omega", Alpha, sans-serif; + content: "\f085"; + color: rgba(98, 76 /* or 54 */, 231, .75); +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.lisp b/swh/web/tests/resources/contents/code/extensions/test.lisp new file mode 100644 index 00000000..949a30a3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.lisp @@ -0,0 +1,22 @@ +#!/usr/bin/env csi + +(defun prompt-for-cd () + "Prompts + for CD" + (prompt-read "Title" 1.53 1 2/4 1.7 1.7e0 2.9E-4 +42 -7 #b001 #b001/100 #o777 #O777 #xabc55 #c(0 -5.6)) + (prompt-read "Artist" &rest) + (or (parse-integer (prompt-read "Rating") :junk-allowed t) 0) + (if x (format t "yes") (format t "no" nil) ;and here comment + ) + ;; second line comment + '(+ 1 2) + (defvar *lines*) ; list of all lines + (position-if-not #'sys::whitespacep line :start beg)) + (quote (privet 1 2 3)) + '(hello world) + (* 5 7) + (1 2 34 5) + (:use "aaaa") + (let ((x 10) (y 20)) + (print (+ x y)) + ) \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ll b/swh/web/tests/resources/contents/code/extensions/test.ll new file mode 100644 index 00000000..d52699da --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ll @@ -0,0 +1,57 @@ +; ModuleID = 'test.c' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] } +%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 } +%struct.what = type { i8, i16 } + +@.str = private unnamed_addr constant [6 x i8] c"foo()\00", align 1 +@e_long = common global i64 0, align 8 +@g_double = common global double 0.000000e+00, align 8 +@.str.1 = private unnamed_addr constant [7 x i8] c"oooooh\00", align 1 +@func_ptr = common global i32 (...)* null, align 8 +@stderr = external global %struct._IO_FILE*, align 8 + +; Function Attrs: nounwind uwtable +define i32 @foo() #0 { + %1 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0)) + ret i32 0 +} + +declare i32 @puts(i8*) #1 + +; Function Attrs: nounwind uwtable +define i32 @main(i32 %argc, i8** %argv) #0 { + %1 = alloca i32, align 4 + %2 = alloca i32, align 4 + %3 = alloca i8**, align 8 + +; <label>:7 ; preds = %0 + %8 = getelementptr inbounds %struct.what, %struct.what* %X, i32 0, i32 0 + store i8 1, i8* %8, align 2 + store i8 49, i8* %b_char, align 1 + %9 = getelementptr inbounds %struct.what, %struct.what* %X, i32 0, i32 1 + store double 1.000000e+01, double* @g_double, align 8 + store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8** %cp_char_ptr, align 8 + store i32 (...)* bitcast (i32 ()* @foo to i32 (...)*), i32 (...)** @func_ptr, align 8 + %10 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0)) + store i32 10, i32* %1, align 4 + br label %66 + +; <label>:63 ; preds = %11 + %64 = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8 + %65 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i32 0, i32 0), %struct._IO_FILE* %64) + store i32 -1, i32* %1, align 4 + br label %66 + +; <label>:66 ; preds = %63, %46, %7 + %67 = load i32, i32* %1, align 4 + ret i32 %67 +} + +declare i32 @printf(i8*, ...) #1 + +declare i32 @fputs(i8*, %struct._IO_FILE*) #1 + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ls b/swh/web/tests/resources/contents/code/extensions/test.ls new file mode 100644 index 00000000..38b33c41 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ls @@ -0,0 +1,38 @@ +# take the first n objects from a list +take = (n, [x, ...xs]:list) --> + | n <= 0 => [] + | empty list => [] + | otherwise => [x] ++ take n - 1, xs + +take 2, [1, 2, 3, 4, 5] + +# Curried functions +take-three = take 3 +take-three [6, 7, 8, 9, 10] + +# Function composition +last-three = reverse >> take-three >> reverse +last-three [1 to 8] + +# List comprehensions and piping +t1 = + * id: 1 + name: 'george' + * id: 2 + name: 'mike' + * id: 3 + name: 'donald' + +t2 = + * id: 2 + age: 21 + * id: 1 + age: 20 + * id: 3 + age: 26 +[{id:id1, name, age} + for {id:id1, name} in t1 + for {id:id2, age} in t2 + where id1 is id2] + |> sort-by \id + |> JSON.stringify \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.lsl b/swh/web/tests/resources/contents/code/extensions/test.lsl new file mode 100644 index 00000000..f9784707 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.lsl @@ -0,0 +1,12 @@ +default +{ + state_entry() + { + llSay(PUBLIC_CHANNEL, "Hello, Avatar!"); + } + + touch_start(integer num_detected) + { + llSay(PUBLIC_CHANNEL, "Touched."); + } +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.lua b/swh/web/tests/resources/contents/code/extensions/test.lua new file mode 100644 index 00000000..e1f4f12a --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.lua @@ -0,0 +1,32 @@ +--[[ +Simple signal/slot implementation +]] +local signal_mt = { + __index = { + register = table.insert + } +} +function signal_mt.__index:emit(... --[[ Comment in params ]]) + for _, slot in ipairs(self) do + slot(self, ...) + end +end +local function create_signal() + return setmetatable({}, signal_mt) +end + +-- Signal test +local signal = create_signal() +signal:register(function(signal, ...) + print(...) +end) +signal:emit('Answer to Life, the Universe, and Everything:', 42) + +--[==[ [=[ [[ +Nested ]] +multi-line ]=] +comment ]==] +[==[ Nested +[=[ multi-line +[[ string +]] ]=] ]==] diff --git a/swh/web/tests/resources/contents/code/extensions/test.m b/swh/web/tests/resources/contents/code/extensions/test.m new file mode 100644 index 00000000..e8063e8c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.m @@ -0,0 +1,45 @@ +n = 20; % number of points +points = [random('unid', 100, n, 1), random('unid', 100, n, 1)]; +len = zeros(1, n - 1); +points = sortrows(points); +%% Initial set of points +plot(points(:,1),points(:,2)); +for i = 1: n-1 + len(i) = points(i + 1, 1) - points(i, 1); +end +while(max(len) > 2 * min(len)) + [d, i] = max(len); + k = on_margin(points, i, d, -1); + m = on_margin(points, i + 1, d, 1); + xm = 0; ym = 0; +%% New point + if(i == 1 || i + 1 == n) + xm = mean(points([i,i+1],1)) + ym = mean(points([i,i+1],2)) + else + [xm, ym] = dlg1(points([k, i, i + 1, m], 1), ... + points([k, i, i + 1, m], 2)) + end + + points = [ points(1:i, :); [xm, ym]; points(i + 1:end, :)]; +end + +%{ + This is a block comment. Please ignore me. +%} + +function [net] = get_fit_network(inputs, targets) + % Create Network + numHiddenNeurons = 20; % Adjust as desired + net = newfit(inputs,targets,numHiddenNeurons); + net.trainParam.goal = 0.01; + net.trainParam.epochs = 1000; + % Train and Apply Network + [net,tr] = train(net,inputs,targets); +end + +foo_matrix = [1, 2, 3; 4, 5, 6]'''; +foo_cell = {1, 2, 3; 4, 5, 6}''.'.'; + +cell2flatten = {1,2,3,4,5}; +flattenedcell = cat(1, cell2flatten{:}); diff --git a/swh/web/tests/resources/contents/code/extensions/test.md b/swh/web/tests/resources/contents/code/extensions/test.md new file mode 100644 index 00000000..b2c2027d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.md @@ -0,0 +1,22 @@ +# hello world + +you can write text [with links](http://example.com) inline or [link references][1]. + +* one _thing_ has *em*phasis +* two __things__ are **bold** + +[1]: http://example.com + +--- + +hello world +=========== + +<this_is inline="xml"></this_is> + +> markdown is so cool + + so are code segments + +1. one thing (yeah!) +2. two thing `i can write code`, and `more` wipee! \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.mel b/swh/web/tests/resources/contents/code/extensions/test.mel new file mode 100644 index 00000000..f30fe92e --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.mel @@ -0,0 +1,25 @@ +proc string[] getSelectedLights() + +{ + string $selectedLights[]; + + string $select[] = `ls -sl -dag -leaf`; + + for ( $shape in $select ) + { + // Determine if this is a light. + // + string $class[] = getClassification( `nodeType $shape` ); + + + if ( ( `size $class` ) > 0 && ( "light" == $class[0] ) ) + { + $selectedLights[ `size $selectedLights` ] = $shape; + } + } + + // Result is an array of all lights included in + + // current selection list. + return $selectedLights; +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.mk b/swh/web/tests/resources/contents/code/extensions/test.mk new file mode 100644 index 00000000..4db94a75 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.mk @@ -0,0 +1,37 @@ +#IMAGE_FILES="*.png|*.jpg" +#SOUND_FILES="*.wav|*.ogg" +#MUSIC_FILES="*.wav|*.ogg" +#BINARY_FILES="*.bin|*.dat" + +Import mojo + +' The main class which expends Mojo's 'App' class: +Class GameApp Extends App + Field player:Player + + Method OnCreate:Int() + Local img:Image = LoadImage("player.png") + Self.player = New Player() + SetUpdateRate(60) + + Return 0 + End + + Method OnUpdate:Int() + player.x += HALFPI + + If (player.x > 100) Then + player.x = 0 + Endif + + Return 0 + End + + Method OnRender:Int() + Cls(32, 64, 128) + player.Draw() + + player = Null + Return 0 + End +End diff --git a/swh/web/tests/resources/contents/code/extensions/test.ml b/swh/web/tests/resources/contents/code/extensions/test.ml new file mode 100644 index 00000000..60d199c9 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ml @@ -0,0 +1,23 @@ +(* This is a +multiline, (* nested *) comment *) +type point = { x: float; y: float };; +let some_string = "this is a string";; +let rec length lst = + match lst with + [] -> 0 + | head :: tail -> 1 + length tail + ;; +exception Test;; +type expression = + Const of float + | Var of string + | Sum of expression * expression (* e1 + e2 *) + | Diff of expression * expression (* e1 - e2 *) + | Prod of expression * expression (* e1 * e2 *) + | Quot of expression * expression (* e1 / e2 *) +class point = + object + val mutable x = 0 + method get_x = x + method private move d = x <- x + d + end;; diff --git a/swh/web/tests/resources/contents/code/extensions/test.moon b/swh/web/tests/resources/contents/code/extensions/test.moon new file mode 100644 index 00000000..6e26b988 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.moon @@ -0,0 +1,37 @@ +print "I am #{math.random! * 100}% sure." + +my_function = (name="something", height=100) -> + print "Hello I am", name + print "My height is", height + +my_function dance: "Tango", partner: "none" + +my_func 5,4,3, -- multi-line arguments + 8,9,10 + +table = { + name: "Bill", + age: 200, + ["favorite food"]: "rice", + :keyvalue, + [1+7]: 'eight' +} + +class Inventory + new: => + @items = {} + + add_item: (name) => + if @items[name] + @items[name] += 1 + else + @items[name] = 1 + +inv = Inventory! +inv\add_item "t-shirt" +inv\add_item "pants" + +import + assert_csrf + require_login + from require "helpers" \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.nim b/swh/web/tests/resources/contents/code/extensions/test.nim new file mode 100644 index 00000000..32cb9cc1 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.nim @@ -0,0 +1,21 @@ +import module1, module2, module3 +from module4 import nil + +type + TFoo = object ## Doc comment + a: int32 + PFoo = ref TFoo + +proc do_stuff314(param_1: TFoo, par2am: var PFoo): PFoo {.exportc: "dostuff" .} = + # Regular comment + discard """ + dfag +sdfg"" +""" + result = nil + +method abc(a: TFoo) = discard 1u32 + 0xabcdefABCDEFi32 + 0o01234567i8 + 0b010 + +discard rawstring"asdf""adfa" +var normalstring = "asdf" +let a: uint32 = 0xFFaF'u32 diff --git a/swh/web/tests/resources/contents/code/extensions/test.nix b/swh/web/tests/resources/contents/code/extensions/test.nix new file mode 100644 index 00000000..0cfa13e1 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.nix @@ -0,0 +1,24 @@ +{ stdenv, foo, bar ? false, ... }: + +/* + * foo + */ + +let + a = 1; # just a comment + b = null; + c = toString 10; +in stdenv.mkDerivation rec { + name = "foo-${version}"; + version = "1.3"; + + configureFlags = [ "--with-foo2" ] ++ stdenv.lib.optional bar "--with-foo=${ with stdenv.lib; foo }" + + postInstall = '' + ${ if true then "--${test}" else false } + ''; + + meta = with stdenv.lib; { + homepage = https://nixos.org; + }; +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.nsi b/swh/web/tests/resources/contents/code/extensions/test.nsi new file mode 100644 index 00000000..3cb91105 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.nsi @@ -0,0 +1,37 @@ +/* + NSIS Scheme + for highlight.js +*/ + +; Includes +!include MUI2.nsh + +; Defines +!define x64 "true" + +; Settings +Name "installer_name" +OutFile "installer_name.exe" +RequestExecutionLevel user +CRCCheck on + +!ifdef ${x64} + InstallDir "$PROGRAMFILES64\installer_name" +!else + InstallDir "$PROGRAMFILES\installer_name" +!endif + +; Pages +!insertmacro MUI_PAGE_INSTFILES + +; Sections +Section "section_name" section_index + nsExec::ExecToLog "calc.exe" +SectionEnd + +; Functions +Function .onInit + DetailPrint "The install button reads $(^InstallBtn)" + DetailPrint 'Here comes a$\n$\rline-break!' + DetailPrint `Escape the dollar-sign: $$` +FunctionEnd \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.p b/swh/web/tests/resources/contents/code/extensions/test.p new file mode 100644 index 00000000..d6a6d2b4 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.p @@ -0,0 +1,34 @@ +@CLASS +base + +@USE +module.p + +@BASE +class + +# Comment for code +@create[aParam1;aParam2][local1;local2] + ^connect[mysql://host/database?ClientCharset=windows-1251] + ^for[i](1;10){ + <p class="paragraph">^eval($i+10)</p> + ^connect[mysql://host/database]{ + $tab[^table::sql{select * from `table` where a='1'}] + $var_Name[some${value}] + } + } + + ^rem{ + Multiline comment with code: $var + ^while(true){ + ^for[i](1;10){ + ^sleep[] + } + } + } + ^taint[^#0A] + +@GET_base[] +## Comment for code + # Isn't comment + $result[$.hash_item1[one] $.hash_item2[two]] \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.pbi b/swh/web/tests/resources/contents/code/extensions/test.pbi new file mode 100644 index 00000000..869b3b30 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.pbi @@ -0,0 +1,29 @@ +; PureBASIC 5 - Syntax Highlighting Example + +Enumeration Test 3 Step 10 + #Constant_One ; Will be 3 + #Constant_Two ; Will be 13 +EndEnumeration + +A.i = #Constant_One +B = A + 3 + +STRING.s = SomeProcedure("Hello World", 2, #Empty$, #Null$) +ESCAPED_STRING$ = ~"An escaped (\\) string!\nNewline..." + +FixedString.s{5} = "12345" + +Macro XCase(Type, Text) + Type#Case(Text) +EndMacro + +StrangeProcedureCall ("This command is split " + + "over two lines") ; Line continuation example + +If B > 3 : X$ = "Concatenation of commands" : Else : X$ = "Using colons" : EndIf + +Declare.s Attach(String1$, String2$) + +Procedure.s Attach(String1$, String2$) + ProcedureReturn String1$+" "+String2$ +EndProcedure diff --git a/swh/web/tests/resources/contents/code/extensions/test.pde b/swh/web/tests/resources/contents/code/extensions/test.pde new file mode 100644 index 00000000..50fe6fa3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.pde @@ -0,0 +1,18 @@ +import java.util.LinkedList; +import java.awt.Point; + +PGraphics pg; +String load; + +void setup() { + size(displayWidth, displayHeight, P3D); + pg = createGraphics(displayWidth*2,displayHeight,P2D); + pg.beginDraw(); + pg.background(255,255,255); + //pg.smooth(8); + pg.endDraw(); +} +void draw(){ + background(255); +} + diff --git a/swh/web/tests/resources/contents/code/extensions/test.php b/swh/web/tests/resources/contents/code/extensions/test.php new file mode 100644 index 00000000..a107a7f4 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.php @@ -0,0 +1,52 @@ +require_once 'Zend/Uri/Http.php'; + +namespace Location\Web; + +interface Factory +{ + static function _factory(); +} + +abstract class URI extends BaseURI implements Factory +{ + abstract function test(); + + public static $st1 = 1; + const ME = "Yo"; + var $list = NULL; + private $var; + + /** + * Returns a URI + * + * @return URI + */ + static public function _factory($stats = array(), $uri = 'http') + { + echo __METHOD__; + $uri = explode(':', $uri, 0b10); + $schemeSpecific = isset($uri[1]) ? $uri[1] : ''; + $desc = 'Multi +line description'; + + // Security check + if (!ctype_alnum($scheme)) { + throw new Zend_Uri_Exception('Illegal scheme'); + } + + $this->var = 0 - self::$st; + $this->list = list(Array("1"=> 2, 2=>self::ME, 3 => \Location\Web\URI::class)); + + return [ + 'uri' => $uri, + 'value' => null, + ]; + } +} + +echo URI::ME . URI::$st1; + +__halt_compiler () ; datahere +datahere +datahere */ +datahere \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.pl b/swh/web/tests/resources/contents/code/extensions/test.pl new file mode 100644 index 00000000..6f3a959d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.pl @@ -0,0 +1,42 @@ +# loads object +sub load +{ + my $flds = $c->db_load($id,@_) || do { + Carp::carp "Can`t load (class: $c, id: $id): '$!'"; return undef + }; + my $o = $c->_perl_new(); + $id12 = $id / 24 / 3600; + $o->{'ID'} = $id12 + 123; + #$o->{'SHCUT'} = $flds->{'SHCUT'}; + my $p = $o->props; + my $vt; + $string =~ m/^sought_text$/; + $items = split //, 'abc'; + $string //= "bar"; + for my $key (keys %$p) + { + if(${$vt.'::property'}) { + $o->{$key . '_real'} = $flds->{$key}; + tie $o->{$key}, 'CMSBuilder::Property', $o, $key; + } + } + $o->save if delete $o->{'_save_after_load'}; + + # GH-117 + my $g = glob("/usr/bin/*"); + + return $o; +} + +__DATA__ +@@ layouts/default.html.ep +<!DOCTYPE html> +<html> + <head><title><%= title %></title></head> + <body><%= content %></body> +</html> +__END__ + +=head1 NAME +POD till the end of file + diff --git a/swh/web/tests/resources/contents/code/extensions/test.pony b/swh/web/tests/resources/contents/code/extensions/test.pony new file mode 100644 index 00000000..ade0bfdf --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.pony @@ -0,0 +1,20 @@ +use "collections" + +class StopWatch + """ + A simple stopwatch class for performance micro-benchmarking + """ + var _s: U64 = 0 + + fun delta(): U64 => + Time.nanos() - _s + +actor LonelyPony + """ + A simple manifestation of the lonely pony problem + """ + var env: Env + let sw: StopWatch = StopWatch + + new create(env': Env) => + env = env \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.pp b/swh/web/tests/resources/contents/code/extensions/test.pp new file mode 100644 index 00000000..7f22820b --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.pp @@ -0,0 +1,33 @@ +# EC2 sample + +class ec2utils { + + # This must include the path to the Amazon EC2 tools + $ec2path = ["/usr/bin", "/bin", "/usr/sbin", "/sbin", + "/opt/ec2/ec2-api-tools/bin", + "/opt/ec2/aws-elb-tools/bin"] + + define elasticip ($instanceid, $ip) + { + exec { "ec2-associate-address-$name": + logoutput => on_failure, + environment => $ec2utils::ec2env, + path => $ec2utils::ec2path, + command => "ec2assocaddr $ip \ + -i $instanceid", + # Only do this when necessary + unless => "test `ec2daddr $ip | awk '{print \$3}'` == $instanceid", + } + } + + mount { "$mountpoint": + device => $devicetomount, + ensure => mounted, + fstype => $fstype, + options => $mountoptions, + require => [ Exec["ec2-attach-volume-$name"], + File["$mountpoint"] + ], + } + +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.properties b/swh/web/tests/resources/contents/code/extensions/test.properties new file mode 100644 index 00000000..f70af5f6 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.properties @@ -0,0 +1,11 @@ +# .properties +! Exclamation mark = comments, too + +key1 = value1 +key2 : value2 +key3 value3 +key\ spaces multiline\ + value4 +empty_key +! Key can contain escaped chars +\:\= = value5 \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.proto b/swh/web/tests/resources/contents/code/extensions/test.proto new file mode 100644 index 00000000..90d4af35 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.proto @@ -0,0 +1,23 @@ +package languages.protobuf; + +option java_package = "org.highlightjs.languages.protobuf"; + +message Customer { + required int64 customer_id = 1; + optional string name = 2; + optional string real_name = 3 [default = "Anonymous"]; + optional Gender gender = 4; + repeated string email_addresses = 5; + + optional bool is_admin = 6 [default = false]; // or should this be a repeated field in Account? + + enum Gender { + MALE = 1, + FEMALE = 2 + } +} + +service CustomerSearch { + rpc FirstMatch(CustomerRequest) returns (CustomerResponse); + rpc AllMatches(CustomerRequest) returns (CustomerResponse); +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.ps1 b/swh/web/tests/resources/contents/code/extensions/test.ps1 new file mode 100644 index 00000000..879d4eac --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ps1 @@ -0,0 +1,11 @@ +$initialDate = [datetime]'2013/1/8' + +$rollingDate = $initialDate + +do { + $client = New-Object System.Net.WebClient + $results = $client.DownloadString("http://not.a.real.url") + Write-Host "$rollingDate.ToShortDateString() - $results" + $rollingDate = $rollingDate.AddDays(21) + $username = [System.Environment]::UserName +} until ($rollingDate -ge [datetime]'2013/12/31') \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.py b/swh/web/tests/resources/contents/code/extensions/test.py new file mode 100644 index 00000000..d0ecaf42 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.py @@ -0,0 +1,12 @@ +# flake8: noqa + +@requires_authorization +def somefunc(param1='', param2=0): + r'''A docstring''' + if param1 > param2: # interesting + print('Gre\'ater') + return (param2 - param1 + 1 + 0b10l) or None + + +class SomeClass: + pass diff --git a/swh/web/tests/resources/contents/code/extensions/test.q b/swh/web/tests/resources/contents/code/extensions/test.q new file mode 100644 index 00000000..6e9e3d90 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.q @@ -0,0 +1,9 @@ +select time, price by date,stock from quote where price=(max;price)fby stock +data:raze value flip trade +select vwap:size wavg price by 5 xbar time.minute from aapl where date within (.z.d-10;.z.d) +f1:{[x;y;z] show (x;y+z);sum 1 2 3} +.z.pc:{[handle] show -3!(`long$.z.p;"Closed";handle)} +// random normal distribution, e.g. nor 10 +nor:{$[x=2*n:x div 2;raze sqrt[-2*log n?1f]*/:(sin;cos)@\:(2*pi)*n?1f;-1_.z.s 1+x]} + +mode:{where g=max g:count each group x} // mode function \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.qml b/swh/web/tests/resources/contents/code/extensions/test.qml new file mode 100644 index 00000000..4f62ab75 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.qml @@ -0,0 +1,49 @@ +/**************************************************************************** +** QML with Highlight.js **/ +import QtQuick 2.5 // good version + +Window { + id: root + width: 1024; height: 600 + color: "black" + property int highestZ: 0 // 0 is lowest, +infinity is highest + property real defaultSize = 200.1 + signal activated(real xPosition, real yPosition) + // show the file picker + FileDialog { + id:fileDialog // an id in a comment should not be detected + title: "Choose a folder with some images" + onAccepted: folderModel.folder = fileUrl + "/" // if this is on property + } + Flickable { + id: flickableproperty + contentHeight: height * surfaceViewportRatio + property real zRestore: 0 + Behavior on scale { NumberAnimation { duration: 200 } } + Repeater { + model: FolderListModel { + id: folderModel + nameFilters: ["*.png", "*.jpg", "*.gif"] + } + Component.onCompleted: { + var x; + x = Math.random() * root.width - width / 2 + rotation = Math.random() * 13 - 6 + if (pinch.scale > 0) { + photoFrame.rotation = 0; + photoFrame.scale = Math.min(root.width, root.height) / Math.max(image.sourceSize.width, image.sourceSize.height) * 0.85 + } else { + photoFrame.rotation = pinch.previousAngle + photoFrame.scale = pinch.previousScale + } + } + function setFrameColor() { + if (currentFrame) + currentFrame.border.color = "black"; + currentFrame = photoFrame; + } + } + } + Timer { id: fadeTimer; interval: 1000; onTriggered: { hfade.start(); vfade.start() } } + Component.onCompleted: fileDialog.open() +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.rb b/swh/web/tests/resources/contents/code/extensions/test.rb new file mode 100644 index 00000000..4f1703ca --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.rb @@ -0,0 +1,13 @@ +# The Greeter class +class Greeter + def initialize(name) + @name = name.capitalize + end + + def salute + puts "Hello #{@name}!" + end +end + +g = Greeter.new("world") +g.salute \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.re b/swh/web/tests/resources/contents/code/extensions/test.re new file mode 100644 index 00000000..27fb81f7 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.re @@ -0,0 +1,47 @@ +/* This is a + multiline + comment */ + +type point = { + x: float, + y: float, +}; + +let some_string = "this is a string"; + +let rec length = lst => + switch (lst) { + | [] => 0 + | [head, ...tail] => 1 + length(tail) + }; + +type result('a, 'b) = + | Ok('a) + | Error('b); + +let promisify = (res: result('a, 'b)) : Js.Promise.t('a) => + switch (res) { + | Ok(a) => Js.Promise.resolve(a) + | Error(b) => Js.Promise.reject(b) + }; + +exception Test; + +module MakeFFI = (T: {type t;}) => { + [@bs.module] external ffi : string => T.t = ""; +}; + +type expression = + | Const(float) + | Var(string) + | Sum(expression, expression) /* e1 + e2 */ + | Diff(expression, expression) /* e1 - e2 */ + | Prod(expression, expression) /* e1 * e2 */ + | Quot(expression, expression); /* e1 / e2 */ + +class point = { + as _; + val mutable x = 0; + pub get_x = x; + pri move = d => x = x + d; +}; diff --git a/swh/web/tests/resources/contents/code/extensions/test.rib b/swh/web/tests/resources/contents/code/extensions/test.rib new file mode 100644 index 00000000..ff23469d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.rib @@ -0,0 +1,25 @@ +FrameBegin 0 +Display "Scene" "framebuffer" "rgb" +Option "searchpath" "shader" "+&:/home/kew" +Option "trace" "int maxdepth" [4] +Attribute "visibility" "trace" [1] +Attribute "irradiance" "maxerror" [0.1] +Attribute "visibility" "transmission" "opaque" +Format 640 480 1.0 +ShadingRate 2 +PixelFilter "catmull-rom" 1 1 +PixelSamples 4 4 +Projection "perspective" "fov" 49.5502811377 +Scale 1 1 -1 + +WorldBegin + +ReadArchive "Lamp.002_Light/instance.rib" +Surface "plastic" +ReadArchive "Cube.004_Mesh/instance.rib" +# ReadArchive "Sphere.010_Mesh/instance.rib" +# ReadArchive "Sphere.009_Mesh/instance.rib" +ReadArchive "Sphere.006_Mesh/instance.rib" + +WorldEnd +FrameEnd diff --git a/swh/web/tests/resources/contents/code/extensions/test.rs b/swh/web/tests/resources/contents/code/extensions/test.rs new file mode 100644 index 00000000..5388d8f9 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.rs @@ -0,0 +1,16 @@ +#[derive(Debug)] +pub enum State { + Start, + Transient, + Closed, +} + +impl From<&'a str> for State { + fn from(s: &'a str) -> Self { + match s { + "start" => State::Start, + "closed" => State::Closed, + _ => unreachable!(), + } + } +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.rsc b/swh/web/tests/resources/contents/code/extensions/test.rsc new file mode 100644 index 00000000..66a5d8f7 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.rsc @@ -0,0 +1,16 @@ +# Берем список DNS серверов из /ip dns + # Проверяем их доступность, +# и только рабочие прописываем в настройки DHCP сервера +:global ActiveDNSServers [] +:local PingResult 0 +:foreach serv in=[/ip dns get servers] do={ + :do {:set PingResult [ping $serv count=3]} on-error={:set PingResult 0} + :if ($PingResult=3) do={ :set ActiveDNSServers ($ActiveDNSServers,$serv) } +# отладочный вывод в журнал + :log info "Server: $serv, Ping-result: $PingResult"; +} + +/ip dhcp-server network set [find address=192.168.254.0/24] dns-server=$ActiveDNSServers + +#--- FIX TTL ---- +/ip firewall mangle chain=postrouting action=change-ttl new-ttl=set:128 comment="NAT hide" diff --git a/swh/web/tests/resources/contents/code/extensions/test.s b/swh/web/tests/resources/contents/code/extensions/test.s new file mode 100644 index 00000000..b01d965f --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.s @@ -0,0 +1,36 @@ +.text + +.global connect +connect: + mov r3, #2 ; s->sin_family = AF_INET + strh r3, [sp] + ldr r3, =server_port ; s->sin_port = server_port + ldr r3, [r3] + strh r3, [sp, #2] + ldr r3, =server_addr ; s->sin_addr = server_addr + ldr r3, [r3] + str r3, [sp, #4] + mov r3, #0 ; bzero(&s->sin_zero) + str r3, [sp, #8] + str r3, [sp, #12] + mov r1, sp ; const struct sockaddr *addr = sp + + ldr r7, =connect_call + ldr r7, [r7] + swi #0 + + add sp, sp, #16 + pop {r0} ; pop sockfd + + pop {r7} + pop {fp, ip, lr} + mov sp, ip + bx lr + +.data +socket_call: .long 281 +connect_call: .long 283 + +/* all addresses are network byte-order (big-endian) */ +server_addr: .long 0x0100007f ; localhost +server_port: .hword 0x0b1a diff --git a/swh/web/tests/resources/contents/code/extensions/test.sas b/swh/web/tests/resources/contents/code/extensions/test.sas new file mode 100644 index 00000000..f97bed9c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.sas @@ -0,0 +1,48 @@ +/********************************************************************** + * Program: example.sas + * Purpose: SAS Example for HighlightJS Plug-in + **********************************************************************/ + +%put Started at %sysfunc(putn(%sysfunc(datetime()), datetime.)); +options + errors = 20 /* Maximum number of prints of repeat errors */ + fullstimer /* Detailed timer after each step execution */ +; + +%let maindir = /path/to/maindir; +%let outdir = &maindir/out.; + +systask command "mkdir -p &outdir." wait; +libname main "&maindir" access = readonly; + +data testing; + input name $ number delimiter = ","; + datalines; + John,1 + Mary,2 + Jane,3 + ; + if number > 1 then final = 0; + else do; + final = 1; + end; +run; + +%macro testMacro(positional, named = value); + %put positional = &positional.; + %put named = &named.; +%mend testMacro; +%testMacro(positional, named = value); + +dm 'clear log output odsresults'; + +proc datasets lib = work kill noprint; quit; +libname _all_ clear; + +data _null_; + set sashelp.macro( + keep = name + where = (scope = "global"); + ); + call symdel(name); +run; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.scad b/swh/web/tests/resources/contents/code/extensions/test.scad new file mode 100644 index 00000000..706ee131 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.scad @@ -0,0 +1,15 @@ +use <write.scad> +include <../common/base.scad> + +//draw a foobar +module foobar(){ + translate([0,-10,0]) + difference(){ + cube([5,10.04,15]); + sphere(r=10,$fn=100); + } +} + +foobar(); +#cube ([5,5,5]); +echo("done"); \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.scala b/swh/web/tests/resources/contents/code/extensions/test.scala new file mode 100644 index 00000000..c33ea43a --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.scala @@ -0,0 +1,58 @@ +/** + * A person has a name and an age. + */ +case class Person(name: String, age: Int) + +abstract class Vertical extends CaseJeu +case class Haut(a: Int) extends Vertical +case class Bas(name: String, b: Double) extends Vertical + +sealed trait Ior[+A, +B] +case class Left[A](a: A) extends Ior[A, Nothing] +case class Right[B](b: B) extends Ior[Nothing, B] +case class Both[A, B](a: A, b: B) extends Ior[A, B] + +trait Functor[F[_]] { + def map[A, B](fa: F[A], f: A => B): F[B] +} + +// beware Int.MinValue +def absoluteValue(n: Int): Int = + if (n < 0) -n else n + +def interp(n: Int): String = + s"there are $n ${color} balloons.\n" + +type ξ[A] = (A, A) + +trait Hist { lhs => + def ⊕(rhs: Hist): Hist +} + +def gsum[A: Ring](as: Seq[A]): A = + as.foldLeft(Ring[A].zero)(_ + _) + +val actions: List[Symbol] = + 'init :: 'read :: 'write :: 'close :: Nil + +trait Cake { + type T; + type Q + val things: Seq[T] + + abstract class Spindler + + def spindle(s: Spindler, ts: Seq[T], reversed: Boolean = false): Seq[Q] +} + +val colors = Map( + "red" -> 0xFF0000, + "turquoise" -> 0x00FFFF, + "black" -> 0x000000, + "orange" -> 0xFF8040, + "brown" -> 0x804000) + +lazy val ns = for { + x <- 0 until 100 + y <- 0 until 100 +} yield (x + y) * 33.33 \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.sci b/swh/web/tests/resources/contents/code/extensions/test.sci new file mode 100644 index 00000000..3f466c88 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.sci @@ -0,0 +1,14 @@ +// A comment +function I = foo(dims, varargin) + d=[1; matrix(dims(1:$-1),-1,1)] + for i=1:size(varargin) + if varargin(i)==[] then + I=[], + return; + end + end +endfunction + +b = cos(a) + cosh(a); +bar_matrix = [ "Hello", "world" ]; +foo_matrix = [1, 2, 3; 4, 5, 6]; diff --git a/swh/web/tests/resources/contents/code/extensions/test.scm b/swh/web/tests/resources/contents/code/extensions/test.scm new file mode 100644 index 00000000..b62a98cb --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.scm @@ -0,0 +1,28 @@ +;; Calculation of Hofstadter's male and female sequences as a list of pairs + +(define (hofstadter-male-female n) +(letrec ((female (lambda (n) + (if (= n 0) + 1 + (- n (male (female (- n 1))))))) + (male (lambda (n) + (if (= n 0) + 0 + (- n (female (male (- n 1)))))))) + (let loop ((i 0)) + (if (> i n) + '() + (cons (cons (female i) + (male i)) + (loop (+ i 1))))))) + +(hofstadter-male-female 8) + +(define (find-first func lst) +(call-with-current-continuation + (lambda (return-immediately) + (for-each (lambda (x) + (if (func x) + (return-immediately x))) + lst) + #f))) diff --git a/swh/web/tests/resources/contents/code/extensions/test.scss b/swh/web/tests/resources/contents/code/extensions/test.scss new file mode 100644 index 00000000..3e6b880f --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.scss @@ -0,0 +1,73 @@ +@import "compass/reset"; + +// variables +$colorGreen: #008000; +$colorGreenDark: darken($colorGreen, 10); + +@mixin container { + max-width: 980px; +} + +// mixins with parameters +@mixin button($color:green) { + @if ($color == green) { + background-color: #008000; + } + @else if ($color == red) { + background-color: #B22222; + } +} + +button { + @include button(red); +} + +div, +.navbar, +#header, +input[type="input"] { + font-family: "Helvetica Neue", Arial, sans-serif; + width: auto; + margin: 0 auto; + display: block; +} + +.row-12 > [class*="spans"] { + border-left: 1px solid #B5C583; +} + +// nested definitions +ul { + width: 100%; + padding: { + left: 5px; right: 5px; + } + li { + float: left; margin-right: 10px; + .home { + background: url('http://placehold.it/20') scroll no-repeat 0 0; + } + } +} + +.banner { + @extend .container; +} + +a { + color: $colorGreen; + &:hover { color: $colorGreenDark; } + &:visited { color: #c458cb; } +} + +@for $i from 1 through 5 { + .span#{$i} { + width: 20px*$i; + } +} + +@mixin mobile { + @media screen and (max-width : 600px) { + @content; + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.sh b/swh/web/tests/resources/contents/code/extensions/test.sh new file mode 100644 index 00000000..f83339a8 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +###### CONFIG +ACCEPTED_HOSTS="/root/.hag_accepted.conf" +BE_VERBOSE=false + +if [ "$UID" -ne 0 ] +then + echo "Superuser rights required" + exit 2 +fi + +genApacheConf(){ + echo -e "# Host ${HOME_DIR}$1/$2 :" +} diff --git a/swh/web/tests/resources/contents/code/extensions/test.sl b/swh/web/tests/resources/contents/code/extensions/test.sl new file mode 100644 index 00000000..e1743e07 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.sl @@ -0,0 +1,15 @@ +#define TEST_DEFINE 3.14 +/* plastic surface shader + * + * Pixie is: + * (c) Copyright 1999-2003 Okan Arikan. All rights reserved. + */ + +surface plastic (float Ka = 1, Kd = 0.5, Ks = 0.5, roughness = 0.1; + color specularcolor = 1;) { + normal Nf = faceforward (normalize(N),I); + Ci = Cs * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * Ks * + specular(Nf,-normalize(I),roughness); + Oi = Os; + Ci *= Oi; +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.smali b/swh/web/tests/resources/contents/code/extensions/test.smali new file mode 100644 index 00000000..f706526d --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.smali @@ -0,0 +1,75 @@ +.class public Lcom/test/Preferences; +.super Landroid/preference/PreferenceActivity; +.source "Preferences.java" + + +# instance fields +.field private PACKAGE_NAME:Ljava/lang/String; + + +# direct methods +.method public constructor <init>()V + .registers 1 + .annotation build Landroid/annotation/SuppressLint; + value = { + "InlinedApi" + } + .end annotation + + .prologue + .line 25 + invoke-direct {p0}, Landroid/preference/PreferenceActivity;-><init>()V + + const-string v4, "ASDF!" + + .line 156 + .end local v0 #customOther:Landroid/preference/Preference; + .end local v1 #customRate:Landroid/preference/Preference; + .end local v2 #hideApp:Landroid/preference/Preference; + :cond_56 + + .line 135 + invoke-static {p1}, Lcom/google/ads/AdActivity;->b(Lcom/google/ads/internal/d;)Lcom/google/ads/internal/d; + + .line 140 + :cond_e + monitor-exit v1 + :try_end_f + .catchall {:try_start_5 .. :try_end_f} :catchall_30 + + .line 143 + invoke-virtual {p1}, Lcom/google/ads/internal/d;->g()Lcom/google/ads/m; + + move-result-object v0 + + iget-object v0, v0, Lcom/google/ads/m;->c:Lcom/google/ads/util/i$d; + + invoke-virtual {v0}, Lcom/google/ads/util/i$d;->a()Ljava/lang/Object; + + move-result-object v0 + + check-cast v0, Landroid/app/Activity; + + .line 144 + if-nez v0, :cond_33 + + .line 145 + const-string v0, "activity was null while launching an AdActivity." + + invoke-static {v0}, Lcom/google/ads/util/b;->e(Ljava/lang/String;)V + + .line 160 + :goto_22 + return-void + + .line 136 + :cond_23 + :try_start_23 + invoke-static {}, Lcom/google/ads/AdActivity;->c()Lcom/google/ads/internal/d; + + move-result-object v0 + + if-eq v0, p1, :cond_e + + return-void +.end method diff --git a/swh/web/tests/resources/contents/code/extensions/test.sml b/swh/web/tests/resources/contents/code/extensions/test.sml new file mode 100644 index 00000000..ece9cef4 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.sml @@ -0,0 +1,25 @@ +structure List : LIST = + struct + + val op + = InlineT.DfltInt.+ + + datatype list = datatype list + + exception Empty = Empty + + fun last [] = raise Empty + | last [x] = x + | last (_::r) = last r + + fun loop ([], []) = EQUAL + | loop ([], _) = LESS + | loop (_, []) = GREATER + | loop (x :: xs, y :: ys) = + (case compare (x, y) of + EQUAL => loop (xs, ys) + | unequal => unequal) + in + loop + end + + end (* structure List *) \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.sqf b/swh/web/tests/resources/contents/code/extensions/test.sqf new file mode 100644 index 00000000..dc13f0d5 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.sqf @@ -0,0 +1,16 @@ +/*** + Arma Scripting File + Edition: 1.66 +***/ + +// Enable eating to improve health. +_unit addAction ["Eat Energy Bar", { + if (_this getVariable ["EB_NumActivation", 0] > 0) then { + _this setDamage (0 max (damage _this - 0.25)); + } else { + hint "You have eaten it all"; + }; + // 4 - means something... + Z_obj_vip = nil; + [_boat, ["Black", 1], true] call BIS_fnc_initVehicle; +}]; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.st b/swh/web/tests/resources/contents/code/extensions/test.st new file mode 100644 index 00000000..4fc419a9 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.st @@ -0,0 +1,39 @@ +Object>>method: num + "comment 123" + | var1 var2 | + (1 to: num) do: [:i | |var| ^i]. + Klass with: var1. + Klass new. + arr := #('123' 123.345 #hello Transcript var $@). + arr := #(). + var2 = arr at: 3. + ^ self abc + +heapExample + "HeapTest new heapExample" + "Multiline + decription" + | n rnd array time sorted | + n := 5000. + "# of elements to sort" + rnd := Random new. + array := (1 to: n) + collect: [:i | rnd next]. + "First, the heap version" + time := Time + millisecondsToRun: [sorted := Heap withAll: array. + 1 + to: n + do: [:i | + sorted removeFirst. + sorted add: rnd next]]. + Transcript cr; show: 'Time for Heap: ' , time printString , ' msecs'. + "The quicksort version" + time := Time + millisecondsToRun: [sorted := SortedCollection withAll: array. + 1 + to: n + do: [:i | + sorted removeFirst. + sorted add: rnd next]]. + Transcript cr; show: 'Time for SortedCollection: ' , time printString , ' msecs' \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.stan b/swh/web/tests/resources/contents/code/extensions/test.stan new file mode 100644 index 00000000..9866f002 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.stan @@ -0,0 +1,39 @@ +// Multivariate Regression Example +// Taken from stan-reference-2.8.0.pdf p.66 + +data { + int<lower=0> N; // num individuals + int<lower=1> K; // num ind predictors + int<lower=1> J; // num groups + int<lower=1> L; // num group predictors + int<lower=1,upper=J> jj[N]; // group for individual + matrix[N,K] x; // individual predictors + row_vector[L] u[J]; // group predictors + vector[N] y; // outcomes +} +parameters { + corr_matrix[K] Omega; // prior correlation + vector<lower=0>[K] tau; // prior scale + matrix[L,K] gamma; // group coeffs + vector[K] beta[J]; // indiv coeffs by group + real<lower=0> sigma; // prediction error scale +} +model { + tau ~ cauchy(0,2.5); + Omega ~ lkj_corr(2); + to_vector(gamma) ~ normal(0, 5); + { + row_vector[K] u_gamma[J]; + for (j in 1:J) + u_gamma[j] <- u[j] * gamma; + beta ~ multi_normal(u_gamma, quad_form_diag(Omega, tau)); + } + { + vector[N] x_beta_jj; + for (n in 1:N) + x_beta_jj[n] <- x[n] * beta[jj[n]]; + y ~ normal(x_beta_jj, sigma); + } +} + +# Note: Octothorpes indicate comments, too! \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.styl b/swh/web/tests/resources/contents/code/extensions/test.styl new file mode 100644 index 00000000..bb1763fd --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.styl @@ -0,0 +1,25 @@ +@import "nib" + +// variables +$green = #008000 +$green_dark = darken($green, 10) + +// mixin/function +container() + max-width 980px + +// mixin/function with parameters +buttonBG($color = green) + if $color == green + background-color #008000 + else if $color == red + background-color #B22222 + +button + buttonBG(red) + +#content, .content + font Tahoma, Chunkfive, sans-serif + background url('hatch.png') + color #F0F0F0 !important + width 100% diff --git a/swh/web/tests/resources/contents/code/extensions/test.subunit b/swh/web/tests/resources/contents/code/extensions/test.subunit new file mode 100644 index 00000000..51501fe3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.subunit @@ -0,0 +1,18 @@ +progress: 28704 +time: 2016-07-05 12:17:02.290433Z +test: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/branch.txt) +time: 2016-07-05 12:17:02.314892Z +successful: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/branch.txt) +time: 2016-07-05 12:17:02.314939Z +time: 2016-07-05 12:17:02.314991Z +test: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/transport.txt) +time: 2016-07-05 12:17:02.315665Z +successful: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/transport.txt) +time: 2016-07-05 12:17:02.315691Z +time: 2016-07-05 12:17:02.315770Z +test: bzrlib.tests.blackbox.test_add.TestAdd.test_add_control_dir(pre-views) +time: 2016-07-05 12:17:02.368936Z +successful: bzrlib.tests.blackbox.test_add.TestAdd.test_add_control_dir(pre-views) [ multipart +] +time: 2016-07-05 12:17:02.368993Z +time: 2016-07-05 12:17:02.369079Z \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.swift b/swh/web/tests/resources/contents/code/extensions/test.swift new file mode 100644 index 00000000..3857e9b3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.swift @@ -0,0 +1,15 @@ +import Foundation + +@objc class Person: Entity { + var name: String! + var age: Int! + + init(name: String, age: Int) { + /* /* ... */ */ + } + + // Return a descriptive string for this person + func description(offset: Int = 0) -> String { + return "\(name) is \(age + offset) years old" + } +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.tap b/swh/web/tests/resources/contents/code/extensions/test.tap new file mode 100644 index 00000000..f0e4a28b --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.tap @@ -0,0 +1,24 @@ +# Hardware architecture: x86_64 +# Timestamp: 2016-06-16 06:23 (GMT+1) +# +TAP version 13 +1..19 +ok 1 - zdtm/static/conntracks # SKIP manual run only +ok 2 - zdtm/static/maps03 # SKIP manual run only +ok 3 - zdtm/static/mlock_setuid +ok 4 - zdtm/static/groups +ok 5 - zdtm/static/maps05 +ok 6 - zdtm/static/pdeath_sig +ok 7 - zdtm/static/xids00 +ok 8 - zdtm/static/proc-self +ok 9 - zdtm/static/file_fown +ok 10 - zdtm/static/eventfs00 +ok 11 - zdtm/static/uptime_grow # SKIP manual run only +ok 12 - zdtm/static/signalfd00 +ok 13 - zdtm/static/inotify_irmap +ok 14 - zdtm/static/fanotify00 +ok 15 - zdtm/static/session00 +ok 16 - zdtm/static/rlimits00 +ok 17 - zdtm/static/maps04 +ok 18 - zdtm/static/pty03 +ok 19 - zdtm/static/pty02 \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.tcl b/swh/web/tests/resources/contents/code/extensions/test.tcl new file mode 100644 index 00000000..0e7ad632 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.tcl @@ -0,0 +1,26 @@ +package json + +source helper.tcl +# randomness verified by a die throw +set ::rand 4 + +proc give::recursive::count {base p} { ; # 2 mandatory params + while {$p > 0} { + set result [expr $result * $base]; incr p -1 + } + return $result +} + +set a {a}; set b "bcdef"; set lst [list "item"] +puts [llength $a$b] + +set ::my::tid($id) $::my::tid(def) +lappend lst $arr($idx) $::my::arr($idx) $ar(key) +lreplace ::my::tid($id) 4 4 +puts $::rand ${::rand} ${::AWESOME::component::variable} + +puts "$x + $y is\t [expr $x + $y]" + +proc isprime x { + expr {$x>1 && ![regexp {^(oo+?)\1+$} [string repeat o $x]]} +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.tex b/swh/web/tests/resources/contents/code/extensions/test.tex new file mode 100644 index 00000000..5a0c86a7 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.tex @@ -0,0 +1,17 @@ +\documentclass{article} +\usepackage[koi8-r]{inputenc} +\hoffset=0pt +\voffset=.3em +\tolerance=400 +\newcommand{\eTiX}{\TeX} +\begin{document} +\section*{Highlight.js} +\begin{table}[c|c] +$\frac 12\, + \, \frac 1{x^3}\text{Hello \! world}$ & \textbf{Goodbye\~ world} \\\eTiX $ \pi=400 $ +\end{table} +Ch\'erie, \c{c}a ne me pla\^\i t pas! % comment \b +G\"otterd\"ammerung~45\%=34. +$$ + \int\limits_{0}^{\pi}\frac{4}{x-7}=3 +$$ +\end{document} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.thrift b/swh/web/tests/resources/contents/code/extensions/test.thrift new file mode 100644 index 00000000..95358676 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.thrift @@ -0,0 +1,41 @@ +namespace * thrift.test + +/** + * Docstring! + */ +enum Numberz +{ + ONE = 1, + TWO, + THREE, + FIVE = 5, + SIX, + EIGHT = 8 +} + +const Numberz myNumberz = Numberz.ONE; +// the following is expected to fail: +// const Numberz urNumberz = ONE; + +typedef i64 UserId + +struct Msg +{ + 1: string message, + 2: i32 type +} +struct NestedListsI32x2 +{ + 1: list<list<i32>> integerlist +} +struct NestedListsI32x3 +{ + 1: list<list<list<i32>>> integerlist +} +service ThriftTest +{ + void testVoid(), + string testString(1: string thing), + oneway void testInit() +} + diff --git a/swh/web/tests/resources/contents/code/extensions/test.ts b/swh/web/tests/resources/contents/code/extensions/test.ts new file mode 100644 index 00000000..bad26e0c --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.ts @@ -0,0 +1,14 @@ +class MyClass { + public static myValue: string; + constructor(init: string) { + this.myValue = init; + } +} +import fs = require("fs"); +module MyModule { + export interface MyInterface extends Other { + myProperty: any; + } +} +declare magicNumber number; +myArray.forEach(() => { }); // fat arrow syntax \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.v b/swh/web/tests/resources/contents/code/extensions/test.v new file mode 100644 index 00000000..482b23e0 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.v @@ -0,0 +1,41 @@ +Inductive seq : nat -> Set := +| niln : seq 0 +| consn : forall n : nat, nat -> seq n -> seq (S n). + +Fixpoint length (n : nat) (s : seq n) {struct s} : nat := + match s with + | niln => 0 + | consn i _ s' => S (length i s') + end. + +Theorem length_corr : forall (n : nat) (s : seq n), length n s = n. +Proof. + intros n s. + + (* reasoning by induction over s. Then, we have two new goals + corresponding on the case analysis about s (either it is + niln or some consn *) + induction s. + + (* We are in the case where s is void. We can reduce the + term: length 0 niln *) + simpl. + + (* We obtain the goal 0 = 0. *) + trivial. + + (* now, we treat the case s = consn n e s with induction + hypothesis IHs *) + simpl. + + (* The induction hypothesis has type length n s = n. + So we can use it to perform some rewriting in the goal: *) + rewrite IHs. + + (* Now the goal is the trivial equality: S n = S n *) + trivial. + + (* Now all sub cases are closed, we perform the ultimate + step: typing the term built using tactics and save it as + a witness of the theorem. *) +Qed. diff --git a/swh/web/tests/resources/contents/code/extensions/test.vala b/swh/web/tests/resources/contents/code/extensions/test.vala new file mode 100644 index 00000000..d0e77631 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.vala @@ -0,0 +1,46 @@ +using DBus; + +namespace Test { + class Foo : Object { + public signal void some_event (); // definition of the signal + public void method () { + some_event (); // emitting the signal (callbacks get invoked) + } + } +} + +/* defining a class */ +class Track : GLib.Object, Test.Foo { /* subclassing 'GLib.Object' */ + public double mass; /* a public field */ + public double name { get; set; } /* a public property */ + private bool terminated = false; /* a private field */ + public void terminate() { /* a public method */ + terminated = true; + } +} + +const ALL_UPPER_CASE = "you should follow this convention"; + +var t = new Track(); // same as: Track t = new Track(); +var s = "hello"; // same as: string s = "hello"; +var l = new List<int>(); // same as: List<int> l = new List<int>(); +var i = 10; // same as: int i = 10; + + +#if (ololo) +Regex regex = /foo/; +#endif + +/* + * Entry point can be outside class + */ +void main () { + var long_string = """ + Example of "verbatim string". + Same as in @"string" in C# + """ + var foo = new Foo (); + foo.some_event.connect (callback_a); // connecting the callback functions + foo.some_event.connect (callback_b); + foo.method (); +} \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.vb b/swh/web/tests/resources/contents/code/extensions/test.vb new file mode 100644 index 00000000..57c5c8bc --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.vb @@ -0,0 +1,42 @@ +Import System +Import System.IO +#Const DEBUG = True + +Namespace Highlighter.Test + ''' <summary>This is an example class.</summary> + Public Class Program + Protected Shared hello As Integer = 3 + Private Const ABC As Boolean = False + +#Region "Code" + ' Cheers! + <STAThread()> _ + Public Shared Sub Main(ByVal args() As String, ParamArray arr As Object) Handles Form1.Click + On Error Resume Next + If ABC Then + While ABC : Console.WriteLine() : End While + For i As Long = 0 To 1000 Step 123 + Try + System.Windows.Forms.MessageBox.Show(CInt("1").ToString()) + Catch ex As Exception ' What are you doing? Well... + Dim exp = CType(ex, IOException) + REM ORZ + Return + End Try + Next + Else + Dim l As New System.Collections.List<String>() + SyncLock l + If TypeOf l Is Decimal And l IsNot Nothing Then + RemoveHandler button1.Paint, delegate + End If + Dim d = New System.Threading.Thread(AddressOf ThreadProc) + Dim a = New Action(Sub(x, y) x + y) + Static u = From x As String In l Select x.Substring(2, 4) Where x.Length > 0 + End SyncLock + Do : Laugh() : Loop Until hello = 4 + End If + End Sub +#End Region + End Class +End Namespace diff --git a/swh/web/tests/resources/contents/code/extensions/test.vbs b/swh/web/tests/resources/contents/code/extensions/test.vbs new file mode 100644 index 00000000..0982529b --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.vbs @@ -0,0 +1,29 @@ +' creating configuration storage and initializing with default values +Set cfg = CreateObject("Scripting.Dictionary") + +' reading ini file +for i = 0 to ubound(ini_strings) + s = trim(ini_strings(i)) + + ' skipping empty strings and comments + if mid(s, 1, 1) <> "#" and len(s) > 0 then + ' obtaining key and value + parts = split(s, "=", -1, 1) + + if ubound(parts)+1 = 2 then + parts(0) = trim(parts(0)) + parts(1) = trim(parts(1)) + + ' reading configuration and filenames + select case lcase(parts(0)) + case "uncompressed""_postfix" cfg.item("uncompressed""_postfix") = parts(1) + case "f" + options = split(parts(1), "|", -1, 1) + if ubound(options)+1 = 2 then + ' 0: filename, 1: options + ff.add trim(options(0)), trim(options(1)) + end if + end select + end if + end if +next \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.vhd b/swh/web/tests/resources/contents/code/extensions/test.vhd new file mode 100644 index 00000000..be1331c3 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.vhd @@ -0,0 +1,41 @@ +/* + * RS-trigger with assynch. reset + */ + +library ieee; +use ieee.std_logic_1164.all; + +entity RS_trigger is + generic (T: Time := 0ns); + port ( R, S : in std_logic; + Q, nQ : out std_logic; + reset, clock : in std_logic ); +end RS_trigger; + +architecture behaviour of RS_trigger is + signal QT: std_logic; -- Q(t) +begin + process(clock, reset) is + subtype RS is std_logic_vector (1 downto 0); + begin + if reset = '0' then + QT <= '0'; + else + if rising_edge(C) then + if not (R'stable(T) and S'stable(T)) then + QT <= 'X'; + else + case RS'(R&S) is + when "01" => QT <= '1'; + when "10" => QT <= '0'; + when "11" => QT <= 'X'; + when others => null; + end case; + end if; + end if; + end if; + end process; + + Q <= QT; + nQ <= not QT; +end architecture behaviour; \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/extensions/test.vim b/swh/web/tests/resources/contents/code/extensions/test.vim new file mode 100644 index 00000000..18d571a0 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.vim @@ -0,0 +1,17 @@ +if foo > 2 || has("gui_running") + syntax on + set hlsearch +endif + +set autoindent + +" switch on highlighting +function UnComment(fl, ll) + while idx >= a:ll + let srclines=getline(idx) + let dstlines=substitute(srclines, b:comment, "", "") + call setline(idx, dstlines) + endwhile +endfunction + +let conf = {'command': 'git'} diff --git a/swh/web/tests/resources/contents/code/extensions/test.wl b/swh/web/tests/resources/contents/code/extensions/test.wl new file mode 100644 index 00000000..aeff95e8 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.wl @@ -0,0 +1,14 @@ +(* ::Package:: *) + +(* Mathematica Package *) + +BeginPackage["SomePkg`"] + +Begin["`Private`"] + +SomeFn[ns_List] := Fold[Function[{x, y}, x + y], 0, Map[# * 2 &, ns]]; +Print[$ActivationKey]; + +End[] (* End Private Context *) + +EndPackage[] diff --git a/swh/web/tests/resources/contents/code/extensions/test.xml b/swh/web/tests/resources/contents/code/extensions/test.xml new file mode 100644 index 00000000..a74d697f --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" + xmlns:moz="http://www.mozilla.org/2006/browser/search/"> + <!-- Created on Tue, 05 Feb 2019 08:17:49 GMT --> + <ShortName>Software Heritage archive</ShortName> + <Description>Possibly the largest source code archive in the world. Covers public GitHub, GitLab, Debian, GNU, Google Code, PyPI and more</Description> + <Url type="text/html" method="get" template="https://archive.softwareheritage.org/browse/search/?q={searchTerms}&with_visit&with_content"/> + <Image width="16" height="16">https://mycroftproject.com/updateos.php/id0/swh.png</Image> + <Developer>Katrin Leinweber</Developer> + <InputEncoding>UTF-8</InputEncoding> + <moz:SearchForm>https://archive.softwareheritage.org/</moz:SearchForm> + <Url type="application/opensearchdescription+xml" rel="self" template="https://mycroftproject.com/updateos.php/id0/swh.xml"/> +</OpenSearchDescription> diff --git a/swh/web/tests/resources/contents/code/extensions/test.xqy b/swh/web/tests/resources/contents/code/extensions/test.xqy new file mode 100644 index 00000000..392f42bf --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.xqy @@ -0,0 +1,30 @@ +xquery version "3.1"; +(:~ + : @author Duncan Paterson + : @version 1.0:) + +declare variable $local:num := math:log10(12345); + +( +let $map := map { 'R': 'red', 'G': 'green', 'B': 'blue' } +return ( + $map?* (: 1. returns all values; same as: map:keys($map) ! $map(.) :), + $map?R (: 2. returns the value associated with the key 'R'; same as: $map('R') :), + $map?('G','B') (: 3. returns the values associated with the key 'G' and 'B' :) +), + +declare function local:city($country as node()*) as element (country) { +for $country in doc('factbook')//country +where $country/@population > 100000000 +let $name := $country/name[1] +for $city in $country//city[population gt 1000000] +group by $name +return + element country { attribute type { $name }, + $city/name } +}; + +return +('A', 'B', 'C') => count(), + +<root>{local:city(.) + $local:num}</root> diff --git a/swh/web/tests/resources/contents/code/extensions/test.yml b/swh/web/tests/resources/contents/code/extensions/test.yml new file mode 100644 index 00000000..49c4939e --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.yml @@ -0,0 +1,39 @@ +--- +# comment +string_1: "Bar" +string_2: 'bar' +string_3: bar +inline_keys_ignored: sompath/name/file.jpg +keywords_in_yaml: + - true + - false + - TRUE + - FALSE + - 21 + - 21.0 + - !!str 123 +"quoted_key": &foobar + bar: foo + foo: + "foo": bar + +reference: *foobar + +multiline_1: | + Multiline + String +multiline_2: > + Multiline + String +multiline_3: " + Multiline string + " + +ansible_variables: "foo {{variable}}" + +array_nested: +- a +- b: 1 + c: 2 +- b +- comment diff --git a/swh/web/tests/resources/contents/code/extensions/test.zep b/swh/web/tests/resources/contents/code/extensions/test.zep new file mode 100644 index 00000000..8142e7f1 --- /dev/null +++ b/swh/web/tests/resources/contents/code/extensions/test.zep @@ -0,0 +1,55 @@ +function testBefore(<Test> a, var b = 5, int c = 10) +{ + a->method1(); + + return b + c; +} + +namespace Test; + +use RuntimeException as RE; + +/** + * Example comment + */ +class Test extends CustomClass implements TestInterface +{ + const C1 = null; + + // Magic constant: http://php.net/manual/ru/language.constants.predefined.php + const className = __CLASS__; + + public function method1() + { + int a = 1, b = 2; + return a + b; + } + + // See fn is allowed like shortcut + public fn method2() -> <Test> + { + call_user_func(function() { echo "hello"; }); + + + [1, 2, 3, 4, 5]->walk( + function(int! x) { + return x * x; + } + ); + + [1, 2, 3, 4, 5]->walk( + function(_, int key) { echo key; } + ); + + array input = [1, 2, 3, 4, 5]; + + input->walk( + function(_, int key) { echo key; } + ); + + + input->map(x => x * x); + + return this; + } +} diff --git a/swh/web/tests/resources/contents/code/filenames/.htaccess b/swh/web/tests/resources/contents/code/filenames/.htaccess new file mode 100644 index 00000000..3bf2af4f --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/.htaccess @@ -0,0 +1,19 @@ +# rewrite`s rules for wordpress pretty url +LoadModule rewrite_module modules/mod_rewrite.so +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . index.php [NC,L] + +ExpiresActive On +ExpiresByType application/x-javascript "access plus 1 days" + +Order Deny,Allow +Allow from All + +<Location /maps/> + RewriteMap map txt:map.txt + RewriteMap lower int:tolower + RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC] + RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND + RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L] +</Location> diff --git a/swh/web/tests/resources/contents/code/filenames/CMakeLists.txt b/swh/web/tests/resources/contents/code/filenames/CMakeLists.txt new file mode 100644 index 00000000..2bbea38c --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.8) +project(cmake_example) + +# Show message on Linux platform +if (${CMAKE_SYSTEM_NAME} MATCHES Linux) + message("Good choice, bro!") +endif() + +# Tell CMake to run moc when necessary: +set(CMAKE_AUTOMOC ON) +# As moc files are generated in the binary dir, +# tell CMake to always look for includes there: +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Widgets finds its own dependencies. +find_package(Qt5Widgets REQUIRED) + +add_executable(myproject main.cpp mainwindow.cpp) +qt5_use_modules(myproject Widgets) diff --git a/swh/web/tests/resources/contents/code/filenames/Dockerfile b/swh/web/tests/resources/contents/code/filenames/Dockerfile new file mode 100644 index 00000000..7f26735a --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/Dockerfile @@ -0,0 +1,56 @@ +# Example instructions from https://docs.docker.com/reference/builder/ +FROM ubuntu:14.04 + +MAINTAINER example@example.com + +ENV foo /bar +WORKDIR ${foo} # WORKDIR /bar +ADD . $foo # ADD . /bar +COPY \$foo /quux # COPY $foo /quux +ARG VAR=FOO + +RUN apt-get update && apt-get install -y software-properties-common\ + zsh curl wget git htop\ + unzip vim telnet +RUN ["/bin/bash", "-c", "echo hello ${USER}"] + +CMD ["executable","param1","param2"] +CMD command param1 param2 + +EXPOSE 1337 + +ENV myName="John Doe" myDog=Rex\ The\ Dog \ + myCat=fluffy + +ENV myName John Doe +ENV myDog Rex The Dog +ENV myCat fluffy + +ADD hom* /mydir/ # adds all files starting with "hom" +ADD hom?.txt /mydir/ # ? is replaced with any single character + +COPY hom* /mydir/ # adds all files starting with "hom" +COPY hom?.txt /mydir/ # ? is replaced with any single character +COPY --from=foo / . + +ENTRYPOINT ["executable", "param1", "param2"] +ENTRYPOINT command param1 param2 + +VOLUME ["/data"] + +USER daemon + +LABEL com.example.label-with-value="foo" +LABEL version="1.0" +LABEL description="This text illustrates \ +that label-values can span multiple lines." + +WORKDIR /path/to/workdir + +ONBUILD ADD . /app/src + +STOPSIGNAL SIGKILL + +HEALTHCHECK --retries=3 cat /health + +SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/filenames/Makefile b/swh/web/tests/resources/contents/code/filenames/Makefile new file mode 100644 index 00000000..cd1ec79d --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/Makefile @@ -0,0 +1,13 @@ +# Makefile + +BUILDDIR = _build +EXTRAS ?= $(BUILDDIR)/extras + +.PHONY: main clean + +main: + @echo "Building main facility..." + build_main $(BUILDDIR) + +clean: + rm -rf $(BUILDDIR)/* diff --git a/swh/web/tests/resources/contents/code/filenames/access.log b/swh/web/tests/resources/contents/code/filenames/access.log new file mode 100644 index 00000000..a9d43251 --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/access.log @@ -0,0 +1 @@ +20.164.151.111 - - [20/Aug/2015:22:20:18 -0400] "GET /mywebpage/index.php HTTP/1.1" 403 772 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1" diff --git a/swh/web/tests/resources/contents/code/filenames/httpd.conf b/swh/web/tests/resources/contents/code/filenames/httpd.conf new file mode 100644 index 00000000..58a2cf03 --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/httpd.conf @@ -0,0 +1,34 @@ +ServerRoot "/etc/httpd" +Listen 80 +Include conf.modules.d/*.conf + +User apache +Group apache + +ServerAdmin root@localhost + +<Directory /> + AllowOverride none + Require all denied +</Directory> + +DocumentRoot "/var/www/html" + +<Directory "/var/www"> + AllowOverride None + Require all granted +</Directory> + +<Directory "/var/www/html"> + Options Indexes FollowSymLinks + + AllowOverride None + + Require all granted +</Directory> + +<IfModule dir_module> + DirectoryIndex index.html +</IfModule> + +IncludeOptional conf.d/*.conf \ No newline at end of file diff --git a/swh/web/tests/resources/contents/code/filenames/nginx.conf b/swh/web/tests/resources/contents/code/filenames/nginx.conf new file mode 100644 index 00000000..adf4b7e9 --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/nginx.conf @@ -0,0 +1,47 @@ +user www www; +worker_processes 2; +pid /var/run/nginx.pid; +error_log /var/log/nginx.error_log debug | info | notice | warn | error | crit; + +events { + connections 2000; + use kqueue | rtsig | epoll | /dev/poll | select | poll; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '"$gzip_ratio"'; + + send_timeout 3m; + client_header_buffer_size 1k; + + gzip on; + gzip_min_length 1100; + + #lingering_time 30; + + server { + server_name one.example.com www.one.example.com; + access_log /var/log/nginx.access_log main; + + rewrite (.*) /index.php?page=$1 break; + + location / { + proxy_pass http://127.0.0.1/; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + charset koi8-r; + } + + location /api/ { + fastcgi_pass 127.0.0.1:9000; + } + + location ~* \.(jpg|jpeg|gif)$ { + root /spool/www; + } + } +} diff --git a/swh/web/tests/resources/contents/code/filenames/nginx.log b/swh/web/tests/resources/contents/code/filenames/nginx.log new file mode 100644 index 00000000..5ec3287c --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/nginx.log @@ -0,0 +1,12 @@ +93.180.71.3 - - [17/May/2015:08:05:32 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)" +93.180.71.3 - - [17/May/2015:08:05:23 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)" +80.91.33.133 - - [17/May/2015:08:05:24 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.17)" +217.168.17.5 - - [17/May/2015:08:05:34 +0000] "GET /downloads/product_1 HTTP/1.1" 200 490 "-" "Debian APT-HTTP/1.3 (0.8.10.3)" +217.168.17.5 - - [17/May/2015:08:05:09 +0000] "GET /downloads/product_2 HTTP/1.1" 200 490 "-" "Debian APT-HTTP/1.3 (0.8.10.3)" +93.180.71.3 - - [17/May/2015:08:05:57 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)" +217.168.17.5 - - [17/May/2015:08:05:02 +0000] "GET /downloads/product_2 HTTP/1.1" 404 337 "-" "Debian APT-HTTP/1.3 (0.8.10.3)" +217.168.17.5 - - [17/May/2015:08:05:42 +0000] "GET /downloads/product_1 HTTP/1.1" 404 332 "-" "Debian APT-HTTP/1.3 (0.8.10.3)" +80.91.33.133 - - [17/May/2015:08:05:01 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.17)" +93.180.71.3 - - [17/May/2015:08:05:27 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)" +217.168.17.5 - - [17/May/2015:08:05:12 +0000] "GET /downloads/product_2 HTTP/1.1" 200 3316 "-" "-" +188.138.60.101 - - [17/May/2015:08:05:49 +0000] "GET /downloads/product_2 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.9.7.9)" diff --git a/swh/web/tests/resources/contents/code/filenames/pf.conf b/swh/web/tests/resources/contents/code/filenames/pf.conf new file mode 100644 index 00000000..3fc2e631 --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/pf.conf @@ -0,0 +1,43 @@ +# from the PF FAQ: http://www.openbsd.org/faq/pf/example1.html + +# macros + +int_if="xl0" + +tcp_services="{ 22, 113 }" +icmp_types="echoreq" + +comp3="192.168.0.3" + +# options + +set block-policy return +set loginterface egress +set skip on lo + +# FTP Proxy rules + +anchor "ftp-proxy/*" + +pass in quick on $int_if inet proto tcp to any port ftp \ + divert-to 127.0.0.1 port 8021 + +# match rules + +match out on egress inet from !(egress:network) to any nat-to (egress:0) + +# filter rules + +block in log +pass out quick + +antispoof quick for { lo $int_if } + +pass in on egress inet proto tcp from any to (egress) \ + port $tcp_services + +pass in on egress inet proto tcp to (egress) port 80 rdr-to $comp3 + +pass in inet proto icmp all icmp-type $icmp_types + +pass in on $int_if diff --git a/swh/web/tests/resources/contents/code/filenames/resolv.conf b/swh/web/tests/resources/contents/code/filenames/resolv.conf new file mode 100644 index 00000000..38ed5d4e --- /dev/null +++ b/swh/web/tests/resources/contents/code/filenames/resolv.conf @@ -0,0 +1,17 @@ +$ORIGIN example.com. ; designates the start of this zone file in the namespace +$TTL 1h ; default expiration time of all resource records without their own TTL value +example.com. IN SOA ns.example.com. username.example.com. ( 2007120710 1d 2h 4w 1h ) +example.com. IN NS ns ; ns.example.com is a nameserver for example.com +example.com. IN NS ns.somewhere.example. ; ns.somewhere.example is a backup nameserver for example.com +example.com. IN MX 10 mail.example.com. ; mail.example.com is the mailserver for example.com +@ IN MX 20 mail2.example.com. ; equivalent to above line, "@" represents zone origin +@ IN MX 50 mail3 ; equivalent to above line, but using a relative host name +example.com. IN A 192.0.2.1 ; IPv4 address for example.com + IN AAAA 2001:db8:10::1 ; IPv6 address for example.com +ns IN A 192.0.2.2 ; IPv4 address for ns.example.com + IN AAAA 2001:db8:10::2 ; IPv6 address for ns.example.com +www IN CNAME example.com. ; www.example.com is an alias for example.com +wwwtest IN CNAME www ; wwwtest.example.com is another alias for www.example.com +mail IN A 192.0.2.3 ; IPv4 address for mail.example.com +mail2 IN A 192.0.2.4 ; IPv4 address for mail2.example.com +mail3 IN A 192.0.2.5 ; IPv4 address for mail3.example.com \ No newline at end of file diff --git a/swh/web/tests/resources/contents/other/extensions/bash-cheatsheet.pdf b/swh/web/tests/resources/contents/other/extensions/bash-cheatsheet.pdf new file mode 100644 index 00000000..1375ecc2 Binary files /dev/null and b/swh/web/tests/resources/contents/other/extensions/bash-cheatsheet.pdf differ diff --git a/swh/web/tests/resources/contents/other/extensions/swh-logo.jpeg b/swh/web/tests/resources/contents/other/extensions/swh-logo.jpeg new file mode 100644 index 00000000..2f49d434 Binary files /dev/null and b/swh/web/tests/resources/contents/other/extensions/swh-logo.jpeg differ diff --git a/swh/web/tests/resources/contents/other/extensions/swh-logo.png b/swh/web/tests/resources/contents/other/extensions/swh-logo.png new file mode 100644 index 00000000..3cbb7196 Binary files /dev/null and b/swh/web/tests/resources/contents/other/extensions/swh-logo.png differ diff --git a/swh/web/tests/resources/contents/other/extensions/swh-logo.webp b/swh/web/tests/resources/contents/other/extensions/swh-logo.webp new file mode 100644 index 00000000..4415a33d Binary files /dev/null and b/swh/web/tests/resources/contents/other/extensions/swh-logo.webp differ diff --git a/swh/web/tests/resources/contents/other/extensions/swh-spinner.gif b/swh/web/tests/resources/contents/other/extensions/swh-spinner.gif new file mode 100644 index 00000000..d4fd2a0d Binary files /dev/null and b/swh/web/tests/resources/contents/other/extensions/swh-spinner.gif differ diff --git a/swh/web/tests/resources/contents/other/extensions/word2vec.ipynb b/swh/web/tests/resources/contents/other/extensions/word2vec.ipynb new file mode 100644 index 00000000..adc8a6cd --- /dev/null +++ b/swh/web/tests/resources/contents/other/extensions/word2vec.ipynb @@ -0,0 +1,197 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Learning word embeddings - word2vec\n", + "\n", + "\\- [Saurabh Mathur](https://saurabhmathur96.github.io/)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The aim of this experiment is to use the algorithm developed by [*Tomas Mikolov et al.*](http://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf) to learn high quality vector representations of text." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The skip-gram model" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Given,\n", + "\n", + "a sequence of words $ w_1, w_2, .., w_T $, predict the next word.\n", + "\n", + "The objective is to maximize average log probability.\n", + "\n", + "\n", + "$$ AverageLogProbability = \\frac{1}{T} \\sum_{t=1}^{T} \\sum_{-c \\leqslant j\\leqslant c, j \\neq 0} log\\ p (w_{t+j} | w_t) $$\n", + "\n", + "where $ c $ is the length of context." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Basic skip-gram model\n", + "\n", + "The basic skip-gram formulation defines $ p (w_{t+j} | w_t) $ in terms of softmax as -\n", + "\n", + "$$ p (wo | wi) = \\frac{ exp(v'^{T} _{wo} \\cdot v_{wi}) }{ \\sum^{W}_{w=1} exp(v'^{T} _{w} \\cdot v_{wi} ) } $$\n", + "\n", + "where $vi$ and $vo$ are input and output word vectors.\n", + "\n", + "This is extremely costly and this impractical as, W is huge ( ~ $10^5-10^7$ terms ). " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There are three proposed methods to get around this limitation.\n", + "- Heirarchial softmax\n", + "- Negative sampling\n", + "- Subsample frequent words" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "I'm using Google's Tensorflow library for the implementation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import tensorflow as tf" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For the data, I'm using the [text8 dataset](http://mattmahoney.net/dc/textdata) which is a 100MB sample of cleaned English Wikipedia dump on Mar. 3, 2006" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import os, urllib\n", + "\n", + " \n", + "def fetch_data(url):\n", + " \n", + " filename = url.split(\"/\")[-1]\n", + " datadir = os.path.join(os.getcwd(), \"data\")\n", + " filepath = os.path.join(datadir, filename)\n", + " \n", + " if not os.path.exists(datadir):\n", + " os.makedirs(datadir)\n", + " if not os.path.exists(filepath):\n", + " urllib.urlretrieve(url, filepath)\n", + " \n", + " return filepath\n", + "\n", + "url = \"http://mattmahoney.net/dc/text8.zip\"\n", + "filepath = fetch_data(url)\n", + "print (\"Data at {0}.\".format(filepath))\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import os, zipfile\n", + "\n", + "def read_data(filename):\n", + " with zipfile.ZipFile(filename) as f:\n", + " data = tf.compat.as_str(f.read(f.namelist()[0])).split()\n", + " return data\n", + "\n", + "\n", + "words = read_data(filepath)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Take only the top $c$ words, mark rest as UNK (unknown)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def build_dataset(words, vocabulary_size):\n", + " count = [[ \"UNK\", -1 ]].extend(\n", + " collections.Counter(words).most_common(vocabulary_size))\n", + " word_to_index = { word: i for i, (word, _) in enumerate(count) }\n", + " data = [word_to_index.get(word, 0) for word in words] # map unknown words to 0\n", + " unk_count = data.count(0) # Number of unknown words\n", + " count[0][1] = unk_count\n", + " index_to_word= dict(zip(word_to_index.values(), word_to_index.keys()))\n", + " \n", + " return data, count, word_to_index, index_to_word\n", + "\n", + "vocabulary_size = 50000\n", + "data, count, word_to_index, index_to_word = build_dataset(words, vocabulary_size)\n", + "print (\"data: {0}\".format(data[:5]))\n", + "print (\"count: {0}\".format(count[:5]))\n", + "print (\"word_to_index: {0}\".format(word_to_index.items()[:5]))\n", + "print (\"index_to_word: {0}\".format(index_to_word.items()[:5]))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/swh/web/urls.py b/swh/web/urls.py index 45491ccf..0485cbc4 100644 --- a/swh/web/urls.py +++ b/swh/web/urls.py @@ -1,74 +1,103 @@ # Copyright (C) 2017-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information import json from django.conf import settings from django.conf.urls import ( url, include, handler400, handler403, handler404, handler500 ) from django.contrib.staticfiles import finders from django.contrib.staticfiles.views import serve from django.shortcuts import render from django.views.generic.base import RedirectView from django_js_reverse.views import urls_js from swh.web.browse.identifiers import swh_id_browse from swh.web.config import get_config from swh.web.common.exc import ( swh_handle400, swh_handle403, swh_handle404, swh_handle500 ) from swh.web.misc.coverage import swh_coverage swh_web_config = get_config() favicon_view = RedirectView.as_view(url='/static/img/icons/swh-logo-32x32.png', permanent=True) def default_view(request): return render(request, "homepage.html") def jslicenses(request): jslicenses_file = finders.find('jssources/jslicenses.json') jslicenses_data = json.load(open(jslicenses_file)) jslicenses_data = sorted(jslicenses_data.items(), key=lambda item: item[0].split('/')[-1]) return render(request, "jslicenses.html", {'jslicenses_data': jslicenses_data}) urlpatterns = [ url(r'^admin/', include('swh.web.admin.urls')), url(r'^favicon\.ico$', favicon_view), url(r'^api/', include('swh.web.api.urls')), url(r'^browse/', include('swh.web.browse.urls')), url(r'^$', default_view, name='swh-web-homepage'), url(r'^jsreverse/$', urls_js, name='js_reverse'), url(r'^(?P<swh_id>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$', swh_id_browse, name='browse-swh-id'), url(r'^coverage/$', swh_coverage, name='swh-coverage'), url(r'^jslicenses/$', jslicenses, name='jslicenses'), ] +# when running end to end tests trough cypress, declare some extra +# endpoints to provide input data for some of those tests +if swh_web_config['e2e_tests_mode']: + from swh.web.tests.data import ( + get_content_code_data_by_ext, + get_content_other_data_by_ext, + get_content_code_data_all_exts, + get_content_code_data_by_filename, + get_content_code_data_all_filenames, + ) # noqa + urlpatterns.append( + url(r'^tests/data/content/code/extension/(?P<ext>.+)/$', + get_content_code_data_by_ext, + name='tests-content-code-extension')) + urlpatterns.append( + url(r'^tests/data/content/other/extension/(?P<ext>.+)/$', + get_content_other_data_by_ext, + name='tests-content-other-extension')) + urlpatterns.append(url(r'^tests/data/content/code/extensions/$', + get_content_code_data_all_exts, + name='tests-content-code-extensions')) + urlpatterns.append( + url(r'^tests/data/content/code/filename/(?P<filename>.+)/$', + get_content_code_data_by_filename, + name='tests-content-code-filename')) + urlpatterns.append(url(r'^tests/data/content/code/filenames/$', + get_content_code_data_all_filenames, + name='tests-content-code-filenames')) + # allow to serve assets through django staticfiles # even if settings.DEBUG is False def insecure_serve(request, path, **kwargs): return serve(request, path, insecure=True, **kwargs) # enable to serve compressed assets through django development server if swh_web_config['serve_assets']: static_pattern = r'^%s(?P<path>.*)$' % settings.STATIC_URL[1:] urlpatterns.append(url(static_pattern, insecure_serve)) handler400 = swh_handle400 # noqa handler403 = swh_handle403 # noqa handler404 = swh_handle404 # noqa handler500 = swh_handle500 # noqa