See #18. Implement foundation for Specs.

What's New:
- Directory structure for specs examples to be tested
- Dynamically generated specs for all tests/sample source code

TODO:
- Fix expected test output file contents to be correct
This commit is contained in:
Glavin Wiechert 2014-12-28 02:29:03 -04:00
parent 264821c30a
commit b147ecd9fa
78 changed files with 2095 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
/* ctest4 */
fm_status fm2000EventHandlingInitialize(fm_int sw);
fm_status fm2000MacTableOverflowStart(fm_int sw);
fm_bool fm2000ProcessMATableEntry( fm_mac_table_work_list *pWork,
fm_int sw,
fm_int index,
fm_thread * event_handler,
fm_uint32 * numUpdates,
fm_event **event);
void foo()
{
Logger log = new Logger();
Logger log= new Logger( );
log.foo.bar = 5;
log.narf.sweat = "cat";
for (i = 0; i<5; i++) bar(i);
}
int this_works(int x);
int bug(int); // BUG: left-aligned
typedef int fooman;
enum FLAGS
{
FLAGS_decimal = 1, // decimal
FLAGS_unsigned = 2, // u or U suffix
FLAGS_long = 4, // l or L suffix
};

View File

@ -0,0 +1,10 @@
class Example
{
Example()
: member(0)
{}
int member;
};

View File

@ -0,0 +1,113 @@
class X : Y {
bool Method (int argument_1, int argument_2)
{
#region something
int foo = 0;
#endregion
if (argument_1 == argument_2)
throw new Exception (Locale.GetText ("They are equal!"));
if (argument_1 < argument_2) {
if (argument_1 * 3 > 4)
return true;
else
return false;
}
//
// This sample helps keep your sanity while using 8-spaces for tabs
//
VeryLongIdentifierWhichTakesManyArguments (
Argument1,
Argument2, Argument3,
NestedCallHere (
MoreNested));
}
bool MyProperty {
get { return x; }
set { x = value; }
}
void AnotherMethod ()
{
Logger log = new Logger();
log.foo.bar = 5;
log.narf.sweat = "cat";
if ((a + 5) != 4) {
}
while (blah) {
if (a)
continue;
b++;
}
}
}
object lockA;
object lockB;
void Foo () {
lock (lockA) {
lock (lockB) {
}
}
}
void Bar () {
lock (lockB) {
lock (lockA) {
}
}
}
// class library
class Blah {
Hashtable ht;
void Foo (int zzz, Entry blah) {
lock (ht) {
ht.Add (zzz, blah);
}
}
void Bar ()
{
lock (ht) {
foreach (Entry e in ht)
EachBar (e);
}
}
virtual void EachBar (Entry e)
{
}
}
// User
class MyBlah {
byte[] box = new byte[6];
box[2] = 56;
void DoStuff ()
{
lock (this) {
int i = GetNumber ();
Entry e = GetEntry ();
Foo (i, e);
}
}
override void EachBar (Entry e)
{
lock (this) {
DoSomething (e);
}
}
}

View File

@ -0,0 +1,3 @@
p {
color: red;
}

View File

@ -0,0 +1,35 @@
class Aligns {
final int SZF = 4;
final int SZ2F = 4;
final int aBarF;
final int someIntsF[];
final int someIntsSzdF[4];
final int[] someMoreIntsF;
final int lotsOfIntsF[][][][][][];
final int[][][][] lotsMoreIntsF;
final Tem<Plate> edVarF;
final int aBarSetF=null;
final int someIntsSetF[]=null;
final int someIntsSzdSetF[4]=null;
final int[] someMoreIntsSetF=null;
final int lotsOfIntsSetF[][][][][][]=null;
final int[][][][] lotsMoreIntsSetF=null;
final Tem<Plate> edVarF=null;
int SZ = 4;
int SZ2 = 4;
int aBar;
int someInts[];
int someIntsSzd[4];
int spacer;
int[] someMoreInts;
int lotsOfInts[][][][][][];
int[][][][] lotsMoreInts;
Tem<Plate> edVar;
int aBarSet=null;
int someIntsSet[]=null;
int someIntsSzdSet[4]=null;
int[] someMoreIntsSet=null;
int lotsOfIntsSet[][][][][][]=null;
int[][][][] lotsMoreIntsSet=null;
Tem<Plate> edVar=null;
}

View File

@ -0,0 +1,4 @@
- item
1. one
2. two
3. three

View File

@ -0,0 +1,30 @@
// Turn the document contents into a single savable lump of data
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
#pragma unused(typeName)
// Produce the data lump:
NSData * retval = [NSKeyedArchiver archivedDataWithRootObject:model];
// If the lump is nil something went wrong
// fill out the error object to explain what wrent wrong
if ( outError != NULL ) {
// The sender wanted an error reported. If there
// was a problem, fill in an NSError object
if (retval == nil) {
// The error object should include an (unhelpful)
// explanation of what happened
NSDictionary * userInfoDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"Internal error formatting data", NSLocalizedDescriptionKey,
@"Archiving of data failed. Probably a bug.", NSLocalizedFailureReasonErrorKey,
@"There's nothing you can do.", NSLocalizedRecoverySuggestionErrorKey, nil];
*outError = [NSError errorWithDomain:LinearInternalErrorDomain
code:linErrCantFormatDocumentData
userInfo:userInfoDict];
} else {
// No problem. Don't supply an error object.
*outError = nil;
}
}
return retval;
}

View File

@ -0,0 +1,21 @@
import math, sys;
def example1():
####This is a long comment. This should be wrapped to fit within 72 characters.
some_tuple=( 1,2, 3,'a' );
some_variable={'long':'Long code lines should be wrapped within 79 characters.',
'other':[math.pi, 100,200,300,9876543210,'This is a long string that goes on'],
'more':{'inner':'This whole logical line should be wrapped.',some_tuple:[1,
20,300,40000,500000000,60000000000000000]}}
return (some_tuple, some_variable)
def example2(): return {'has_key() is deprecated':True}.has_key({'f':2}.has_key(''));
class Example3( object ):
def __init__ ( self, bar ):
#Comments should have a space after the hash.
if bar : bar+=1; bar=bar* bar ; return bar
else:
some_string = """
Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
return (sys.path, some_string)

View File

@ -0,0 +1,10 @@
hello derek how is it going?
for c, i in "Hello World!"
k = 1+1- 2>=3<= 4>5 <6
for c, i in "Hello World"
k = (a,b)-> if b? return a
f = b()[0]
for c, i in "Hello World"
f(b())

View File

@ -0,0 +1,3 @@
p {
color: red;
}

View File

@ -0,0 +1,10 @@
{{#if}}
{{#each}}
{{#if}}
content
{{/if}}
{{#if}}
content
{{/if}}
{{/each}}
{{/if}}

View File

@ -0,0 +1,18 @@
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Shopping List for <%= @date.strftime('%A, %d %B %Y') %></title>
</head>
<body>
<h1>Shopping List for <%= @date.strftime('%A, %d %B %Y') %></h1>
<p>You need to buy:</p>
<ul>
<% for @item in @items %>
<li><%= h(@item) %></li>
<% end %>
</ul>
</body>
</html>

View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<h1>Hello</h1>
<p>
World!
</p>
</body>
</html>

View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<h1>Hello</h1>
<p>
World!
</p>
</body>
</html>

View File

@ -0,0 +1,3 @@
function hell() {
console.log('world');
}

View File

@ -0,0 +1,3 @@
function hell() {
console.log('world');
}

View File

@ -0,0 +1,9 @@
{
"indent_size": 2,
"indent_char": " ", // test
"indent_level": 0,
"indent_with_tabs": false, /* test */
"preserve_newlines": true,
"max_preserve_newlines": 2, /* test *
"jslint_happy": true
}

View File

@ -0,0 +1,4 @@
Q($.ajax(...))
.catch(function (response) {
console.error(response);
});

View File

@ -0,0 +1,33 @@
a {
line-height: @headerHeight;
display: block;
padding: 0px 15px;
font-size: 16px;
button {
font-size: 16px;
}
&:link {
color: @white;
text-decoration: none;
}
&:visited {
color: @white;
}
&:hover {
color: @orange;
}
&.green {
color: @green;
&:hover {
color: @white;
background-color: @green;
}
}
}

View File

@ -0,0 +1,169 @@
// main: style.less
@import (reference)"variables.less";
@import (reference)"mixins.less";
.modal {
position: fixed;
height: 100%;
width: 100%;
background-color: fade(@black, 70%);
z-index: 10;
opacity: 0;
display: none;
.innerModal {
margin: auto;
background-color: @white;
overflow: hidden;
-webkit-transform: translateY(-100%);
-moz-transform: translateY(-100%);
-ms-transform: translateY(-100%);
-o-transform: translateY(-100%);
transform: translateY(-100%);
.fa {
float: right;
color: @white;
background-color: firebrick;
padding: 5px 7px;
border-radius: 20px;
&:hover {
background-color: lighten(@black, 50%);
cursor: pointer;
}
&:active {
background-color: lighten(@black, 25%);
}
}
}
&.modal-2text {
.innerModal {
width: @container-width;
margin-top: 50px;
height: 75%;
padding: 10px 25px;
background-color: gainsboro;
border-radius: 4px;
h2 {
margin: 0px 0px 7px 0px;
}
div {
height: 70%;
overflow-y: scroll;
background-color: @white;
padding: 15px;
border-radius: 4px;
}
.large-cta {
margin-top: 25px;
}
}
}
}
#modal-video {
.innerModal {
left: 10%;
margin-top: 30px;
width: 1000px;
background-color: lighten(@black, 25%);
iframe {
width: 600px;
height: 340px;
margin: 2% auto;
}
//container
> div {
text-align: center;
a {
.styleLinks(@white, darken(@white, 10%));
padding: 5px;
text-transform: uppercase;
&:hover {
background-color: fade(@white, 15%);
}
&:active {
background-color: fade(@white, 30%);
}
}
h3 {
color: @white;
font-size: 3em;
margin: 20px auto;
}
button {
margin-bottom: 50px;
}
}
}
}
.slideIn {
.animation(SlideIn, 0.5s);
}
@-webkit-keyframes SlideIn {
0% {
.transform(translateY(-100%));
}
100% {
.transform(translateY(0px));
}
}
.fadeIn {
display: block;
.animation(FadeIn, 0.5s);
}
@-webkit-keyframes FadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.slideOut {
.animation(SlideOut, 0.5s);
}
@-webkit-keyframes SlideOut {
0% {
.transform(translateY(0%));
}
100% {
.transform(translateY(-100%));
}
}
.fadeOut {
.animation(FadeOut, 0.5s);
}
@-webkit-keyframes FadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
display: none;
}
}

View File

@ -0,0 +1,9 @@
// Breaks (fixed now)
.mixin(@variable, @anotherVariable) {
}
// Works
.mixin(@variable; @anotherVariable) {
}
// Ok
.mixin(@variable) {
}

View File

@ -0,0 +1,20 @@
section#photo-details {
width: 1140px;
margin: 60px auto 70px auto;
}
div.photo-view {
text-align: center;
figure {
box-shadow: 0 0 3px 1px rgba(0,0,0,0.75)
;
display : inline-block;
margin : 0 0 60px;
padding
: 0;
img {
display: block;
}
}
}

View File

@ -0,0 +1,9 @@
.animal {
color: red;
}
.dog {
&:extend(.animal);
&:hover {
color: green;
}
}

View File

@ -0,0 +1,7 @@
- item
- item
- item
1. one
2. two
2. three

View File

@ -0,0 +1,16 @@
<h1>{{header}}</h1>
{{#bug}}
{{/bug}}
{{#items}}
{{#first}}
<li><strong>{{name}}</strong></li>
{{/first}}
{{#link}}
<li><a href="{{url}}">{{name}}</a></li>
{{/link}}
{{/items}}
{{#empty}}
<p>The list is empty.</p>
{{/empty}}

View File

@ -0,0 +1,12 @@
#!/usr/bin/env perl
use strict;
use warnings;
if(1){
my $x = 'y';
my $foo = 'bar';
# comment
print('Hello, '.'World!')
}

View File

@ -0,0 +1,32 @@
<?php
$hello = "world";
if (!isset($_SESSION)) session_start();
require_once("sql.req.php");
// friend requests
$q = $mysqli->query("");
$num = $q->num_rows;
echo '<a href="notifications.php">';
if ($num>0) { echo '<i class="fa fa-star white"></i>';
}else { echo '<i class="fa fa-star-o"></i>'; }
echo '</a>';
// new messages
$q = $mysqli->query("");
$num = $q->num_rows;
echo '<a href="messages.php">';
if ($num>0) {
echo '<i class="fa fa-envelope white"></i>';
}else {
echo '<i class="fa fa-envelope-o"></i>';
}
echo '</a>';
?>

View File

@ -0,0 +1,4 @@
<?php
function add($a, $b) {
return $a +$b; }
echo add(1,2);

View File

@ -0,0 +1,19 @@
<?php
class Date
{
const FORMAT_FULL = 'full';
const FORMAT_LONG = 'long';
const FORMAT_MEDIUM = 'medium';
const FORMAT_SHORT = 'short';
public static function formatDate($time, $format)
{
if(!$time || $time == null)
{
return '';
}
return $time;
}
}

View File

@ -0,0 +1,25 @@
#!/usr/bin/env ruby
conn_hash = { :hosts => [
{:login => login, :passcode => passcode, :host => host, :port => port},
],
:reliable => false, # Override default
:connect_headers => conn_hdrs,
}
hash = { :hosts => [
{:login => user, :passcode => password, :host => 'noonehome', :port => 2525},
{:login => user, :passcode => password, :host => host, :port => port},
],
:logger => mylog, # This enables callback logging!
:max_reconnect_attempts => 5,
}

View File

@ -0,0 +1,4 @@
.example(){
.base-apple(); // Sets base apple color to red
.apple-color(@color-green); // Sets apple color to green
}

View File

@ -0,0 +1,6 @@
a {
line-height: 56px;
&:hover {
color: blue;
}
}

View File

@ -0,0 +1,12 @@
#cta {
.container {
.cta--primary {
&:visited {
//whatever
}
&::before {
//whatever
}
}
}
}

View File

@ -0,0 +1 @@
SELECT ca.proj_id AS proj_id, ca.ca_name AS proj_name, ca.ca_date_start AS proj_start, ca.ca_date_end AS proj_end,(SELECT COUNT(*) FROM rotations r WHERE r.proj_id = proj_id AND r.r_status = 'R' GROUP BY r.proj_id) r_count, (SELECT count(*) FROM rotations r WHERE r.proj_id = proj_id AND r.channel_id = 24 ) r_rtb_count FROM projs ca, clients c, proj_auth caa WHERE ca.client_id = 12345 AND ca.client_id = c.client_id AND ca_type = 'zzz' AND c.agency_id = 0 AND ca.client_id = NVL( caa.client_id, ca.client_id ) AND proj_id = NVL( caa.proj_id, proj_id ) AND caa.contact_id = 7890

View File

@ -0,0 +1 @@
SELECT ca.proj_id AS proj_id, ca.ca_name AS proj_name, ca.ca_date_start AS proj_start, ca.ca_date_end AS proj_end,(SELECT COUNT(*) FROM rotations r WHERE r.proj_id = proj_id AND r.r_status = 'R' GROUP BY r.proj_id) r_count, (SELECT count(*) FROM rotations r WHERE r.proj_id = proj_id AND r.channel_id = 24 ) r_rtb_count FROM projs ca, clients c, proj_auth caa WHERE ca.client_id = 12345 AND ca.client_id = c.client_id AND ca_type = 'zzz' AND c.agency_id = 0 AND ca.client_id = NVL( caa.client_id, ca.client_id ) AND proj_id = NVL( caa.proj_id, proj_id ) AND caa.contact_id = 7890

View File

@ -0,0 +1,5 @@
INSERT INTO client (host, description, created_at) VALUES('hallpclnx', 'My linux machine', CURRENT_TIMESTAMP);
INSERT INTO thread (thread, description, created_at, client_id) VALUES(1, 'Living room camera', CURRENT_TIMESTAMP, 1);
INSERT INTO thread (thread, description, created_at, client_id) VALUES(2, 'Porch camera', CURRENT_TIMESTAMP, 1);
INSERT INTO thread (thread, description, created_at, client_id) VALUES(2, 'Garden camera', CURRENT_TIMESTAMP, 1);
INSERT INTO client (host, description, created_at) VALUES('shedpclnx', 'My shed linux machine', CURRENT_TIMESTAMP);

View File

@ -0,0 +1,8 @@
module TestModule {
export class A {
constructor(private a: string) {
}
}
export class B extends A {
}
};

View File

@ -1,4 +1,4 @@
AtomBeautify = require '../lib/atom-beautify'
Beautify = require '../lib/beautify'
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#

View File

@ -0,0 +1,135 @@
Beautify = require '../lib/beautify'
beautifier = require "../lib/language-options"
languages = beautifier.languages
defaultLanguageOptions = beautifier.defaultLanguageOptions
fs = require "fs"
path = require "path"
# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.
describe "BeautifyLanguages", ->
optionsDir = path.resolve(__dirname, "../examples")
# Activate all of the languages
allLanguages = [
"c", "coffee-script", "css", "html",
"java", "javascript", "json", "less",
"mustache", "objective-c", "perl", "php",
"python", "ruby", "sass", "sql",
"typescript", "xml", "csharp", "gfm"
]
beforeEach ->
for lang in allLanguages
do (lang) ->
waitsForPromise ->
atom.packages.activatePackage("language-#{lang}")
###
Directory structure:
- examples
- config1
- lang1
- original
- 1-test.ext
- expected
- 1-test.ext
- lang2
- config2
###
# All Configurations
configs = fs.readdirSync(optionsDir)
for config in configs
do (config) ->
# Generate the path to where all of the languages are
langsDir = path.resolve(optionsDir, config)
optionStats = fs.lstatSync(langsDir)
# Confirm that this path is a directory
if optionStats.isDirectory()
# Create testing group for configuration
describe "when using configuration '#{config}'", ->
# All Languages for configuration
langNames = fs.readdirSync(langsDir)
for lang in langNames
do (lang) ->
# Generate the path to where al of the tests are
testsDir = path.resolve(langsDir, lang)
langStats = fs.lstatSync(testsDir)
# Confirm that this path is a directory
if langStats.isDirectory()
# Original
originalDir = path.resolve(testsDir, "original")
if not fs.existsSync(originalDir)
console.warn("Directory for test originals/inputs not found." +
" Making it at #{originalDir}.")
fs.mkdirSync(originalDir)
# Expected
expectedDir = path.resolve(testsDir, "expected")
if not fs.existsSync(expectedDir)
console.warn("Directory for test expected/results not found." +
"Making it at #{expectedDir}.")
fs.mkdirSync(expectedDir)
# Language group tests
describe "when beautifying language '#{lang}'", ->
# All tests for language
testNames = fs.readdirSync(originalDir)
for testFileName in testNames
do (testFileName) ->
ext = path.extname(testFileName)
testName = path.basename(testFileName, ext)
# Confirm this is a test
it "#{testName}", ->
# Generate paths to test files
originalTestPath = path.resolve(originalDir, testFileName)
expectedTestPath = path.resolve(expectedDir, testFileName)
# Get contents of original test file
originalContents = fs.readFileSync(originalTestPath)?.toString()
# Check if there is a matching expected test resut
if not fs.existsSync(expectedTestPath)
throw new Error("No matching expected test result found for '#{testName}' " +
"at '#{expectedTestPath}'. Creating it from original.")
# err = fs.writeFileSync(expectedTestPath, originalContents)
# throw err if err
# Get contents of expected test file
expectedContents = fs.readFileSync(expectedTestPath)?.toString()
# expect(expectedContents).not.toEqual originalContents
# expect(atom.grammars.getGrammars()).toEqual []
grammar = atom.grammars.selectGrammar(originalTestPath, originalContents)
# expect(grammar).toEqual("test")
grammarName = grammar.name
editorOptions =
indent_size: 4
indent_char: " "
indent_with_tabs: false
allOptions = [editorOptions]
beautifyCompleted = false
completionFun = (text) ->
if text instanceof Error
return beautifyCompleted = text # text == Error
expect(typeof text).toEqual "string"
expect(text).toEqual expectedContents
beautifyCompleted = true
runs ->
try
beautifier.beautify originalContents, grammarName, allOptions, completionFun
catch e
beautifyCompleted = e
waitsFor(->
if beautifyCompleted instanceof Error
throw beautifyCompleted
else
return beautifyCompleted
, "Waiting for beautification to complete", 5000)