This repository has been archived by the owner on Aug 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
136 lines (122 loc) · 5.47 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html>
<head>
<title>java-json-test-writer</title>
<link rel="stylesheet" href="stylesheets/bootstrap.min.css" type="text/css" charset="utf-8" />
</head>
<body>
<a href="https://github.com/dallasgutauckis/java-json-test-writer"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
<div class="container">
<div class="content">
<h1>java-json-test-writer</h1>
<em>by <a href="http://dallasgutauckis.com">Dallas Gutauckis</a></em>
<form method="post">
<fieldset>
<div class="row">
<div class="span4">
<h3>Variable name</h3>
<input type="text" name="variable" value="<?php if ( isset( $_POST['variable'] ) ) { echo $_POST['variable']; } ?>"/>
</div>
</div>
<div class="row">
<div class="span10">
<h3>Convert underscore to lowerCamelCase?</h3>
<input type="checkbox" name="ucWords" value="yeah" <?php if ( isset( $_POST['ucWords'] ) && $_POST['ucWords'] == 'yeah' ) { echo "checked=\"1\""; } ?>/>
</div>
<div class="span10">
<h3>Use bean notation (requires camelCase)</h3>
<input type="checkbox" name="beanify" value="yeah" <?php if ( isset( $_POST['beanify'] ) && $_POST['beanify'] == 'yeah' ) { echo "checked=\"1\""; } ?>/>
</div>
</div>
<div class="row">
<div class="span10">
<h3>JSON</h3>
<textarea rows="20" class="span10" name="input"><?php if ( isset( $_POST['input'] ) ) { echo $_POST['input']; } ?></textarea>
</div>
</div>
<div class="actions">
<input type="submit" name="submit" class="btn primary" value="Build" />
</div>
</fieldset>
</form>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- java-json-test-writer header -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-7874761747975813"
data-ad-slot="9345280686"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br /><br />
<pre><?php
if ( isset( $_POST['input'] ) ) {
$src = json_decode( $_POST['input'] );
$ucWords = $_POST['ucWords'] == "yeah";
$beanify = $_POST['beanify'] == 'yeah';
printAssert( $_POST['variable'], $src, $ucWords, $beanify );
}
function println( $text ) {
echo $text. "\r\n";
}
function getKeyPathString( $keyPath, $key ) {
return (count($keyPath) > 0 ? implode( '.', $keyPath ) . '.' : '') . $key;
}
function printAssertEquals( $keyPath, $key, $value ) {
println( 'assertEquals(' . $value . ', ' . getKeyPathString( $keyPath, $key ) . ');' );
}
function printAssert( $key, $value, $ucWords, $beanify, $keyPath = null ) {
$localBeanify = $beanify && $keyPath !== null;
if ( $ucWords || $localBeanify ) {
$key = preg_replace( '/_(.?)/e',"strtoupper('$1')", $key );
}
if ( $localBeanify ) {
$key = 'get' . ucwords( $key ) . '()';
}
if ( $keyPath === null ) {
$keyPath = array();
}
switch ( gettype( $value ) ) {
case 'NULL':
println( 'assertNull(' . getKeyPathString( $keyPath, $key ) . ');' );
break;
case 'boolean':
println( 'assert' . ( $value ? 'True' : 'False' ) . '(' . getKeyPathString( $keyPath, $key ) . ');' );
break;
case 'integer':
printAssertEquals( $keyPath, $key, $value );
break;
case 'double':
println( 'assertEquals(' . $value . ', ' . getKeyPathString( $keyPath, $key ) . ', 0d);' );
break;
case 'string':
printAssertEquals( $keyPath, $key, '"' . $value . '"' );
break;
case 'array':
foreach ( $value as $index => $itemValue ) {
printAssert( $key . '.get(' . $index . ')', $itemValue, $ucWords, $beanify, $keyPath );
}
break;
case 'object':
$newIndex = count( $keyPath );
$keyPath[$newIndex] = $key;
foreach ( $value as $itemKey => $itemValue ) {
printAssert( $itemKey, $itemValue, $ucWords, $beanify, $keyPath );
}
unset( $keyPath[$newIndex] );
break;
}
}
?>
</pre>
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-401905-9', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>