How to use found method in storybook-root

Best JavaScript code snippet using storybook-root

re_tests.py

Source:re_tests.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- mode: python -*-3# $Id: re_tests.py,v 1.1 2005/10/05 20:19:28 eytanadar Exp $45# Re test suite and benchmark suite v1.567# The 3 possible outcomes for each pattern8[SUCCEED, FAIL, SYNTAX_ERROR] = range(3)910# Benchmark suite (needs expansion)11#12# The benchmark suite does not test correctness, just speed. The13# first element of each tuple is the regex pattern; the second is a14# string to match it against. The benchmarking code will embed the15# second string inside several sizes of padding, to test how regex16# matching performs on large strings.1718benchmarks = [19 ('Python', 'Python'), # Simple text literal20 ('.*Python', 'Python'), # Bad text literal21 ('.*Python.*', 'Python'), # Worse text literal22 ('.*(Python)', 'Python'), # Bad text literal with grouping2324 ('(Python|Perl|Tcl', 'Perl'), # Alternation25 ('(Python|Perl|Tcl)', 'Perl'), # Grouped alternation26 ('(Python)\\1', 'PythonPython'), # Backreference27 ('([0a-z][a-z]*,)+', 'a5,b7,c9,'), # Disable the fastmap optimization28 ('([a-z][a-z0-9]*,)+', 'a5,b7,c9,') # A few sets29]3031# Test suite (for verifying correctness)32#33# The test suite is a list of 5- or 3-tuples. The 5 parts of a34# complete tuple are:35# element 0: a string containing the pattern36# 1: the string to match against the pattern37# 2: the expected result (SUCCEED, FAIL, SYNTAX_ERROR)38# 3: a string that will be eval()'ed to produce a test string.39# This is an arbitrary Python expression; the available40# variables are "found" (the whole match), and "g1", "g2", ...41# up to "g99" contain the contents of each group, or the42# string 'None' if the group wasn't given a value, or the43# string 'Error' if the group index was out of range;44# also "groups", the return value of m.group() (a tuple).45# 4: The expected result of evaluating the expression.46# If the two don't match, an error is reported.47#48# If the regex isn't expected to work, the latter two elements can be omitted.4950tests = [51 # Test ?P< and ?P= extensions52 ('(?P<foo_123', '', SYNTAX_ERROR), # Unterminated group identifier53 ('(?P<1>a)', '', SYNTAX_ERROR), # Begins with a digit54 ('(?P<!>a)', '', SYNTAX_ERROR), # Begins with an illegal char55 ('(?P<foo!>a)', '', SYNTAX_ERROR), # Begins with an illegal char5657 # Same tests, for the ?P= form58 ('(?P<foo_123>a)(?P=foo_123', 'aa', SYNTAX_ERROR),59 ('(?P<foo_123>a)(?P=1)', 'aa', SYNTAX_ERROR),60 ('(?P<foo_123>a)(?P=!)', 'aa', SYNTAX_ERROR),61 ('(?P<foo_123>a)(?P=foo_124', 'aa', SYNTAX_ERROR), # Backref to undefined group6263 ('(?P<foo_123>a)', 'a', SUCCEED, 'g1', 'a'),64 ('(?P<foo_123>a)(?P=foo_123)', 'aa', SUCCEED, 'g1', 'a'),6566 # Test octal escapes67 ('\\1', 'a', SYNTAX_ERROR), # Backreference68 ('[\\1]', '\1', SUCCEED, 'found', '\1'), # Character69 ('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'),70 ('\\141', 'a', SUCCEED, 'found', 'a'),71 #('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'),7273 # Test \0 is handled everywhere74 (r'\0', '\0', SUCCEED, 'found', '\0'),75 (r'[\0a]', '\0', SUCCEED, 'found', '\0'),76 (r'[a\0]', '\0', SUCCEED, 'found', '\0'),77 (r'[^a\0]', '\0', FAIL),7879 # Test various letter escapes80 #(r'\a[\b]\f\n\r\t\v', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'),81 #(r'[\a][\b][\f][\n][\r][\t][\v]', '\a\b\f\n\r\t\v', SUCCEED, 'found', '\a\b\f\n\r\t\v'),82 (r'\u', '', SYNTAX_ERROR), # A Perl escape83 #(r'\c\e\g\h\i\j\k\m\o\p\q\y\z', 'ceghijkmopqyz', SUCCEED, 'found', 'ceghijkmopqyz'),84 (r'\xff', '\377', SUCCEED, 'found', chr(255)),85 #(r'\x00ffffffffffffff', '\377', SUCCEED, 'found', chr(255)),86 #(r'\x00f', '\017', SUCCEED, 'found', chr(15)),87 #(r'\x00fe', '\376', SUCCEED, 'found', chr(254)),8889 (r"^\w+=(\\[\000-\277]|[^\n\\])*", "SRC=eval.c g.c blah blah blah \\\\\n\tapes.c",90 SUCCEED, 'found', "SRC=eval.c g.c blah blah blah \\\\"),9192 # Test that . only matches \n in DOTALL mode93 ('a.b', 'acb', SUCCEED, 'found', 'acb'),94 ('a.b', 'a\nb', FAIL),95 ('a.*b', 'acc\nccb', FAIL),96 ('a.{4,5}b', 'acc\nccb', FAIL),97 ('a.b', 'a\rb', SUCCEED, 'found', 'a\rb'),98 #('a.b(?s)', 'a\nb', SUCCEED, 'found', 'a\nb'),99 ('a.*(?s)b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),100 ('(?s)a.{4,5}b', 'acc\nccb', SUCCEED, 'found', 'acc\nccb'),101 ('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'),102103 (')', '', SYNTAX_ERROR), # Unmatched right bracket104 ('', '', SUCCEED, 'found', ''), # Empty pattern105 ('abc', 'abc', SUCCEED, 'found', 'abc'),106 ('abc', 'xbc', FAIL),107 ('abc', 'axc', FAIL),108 ('abc', 'abx', FAIL),109 ('abc', 'xabcy', SUCCEED, 'found', 'abc'),110 ('abc', 'ababc', SUCCEED, 'found', 'abc'),111 ('ab*c', 'abc', SUCCEED, 'found', 'abc'),112 ('ab*bc', 'abc', SUCCEED, 'found', 'abc'),113 ('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'),114 ('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),115 ('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'),116 ('ab+bc', 'abc', FAIL),117 ('ab+bc', 'abq', FAIL),118 ('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),119 ('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'),120 ('ab?bc', 'abc', SUCCEED, 'found', 'abc'),121 ('ab?bc', 'abbbbc', FAIL),122 ('ab?c', 'abc', SUCCEED, 'found', 'abc'),123 ('^abc$', 'abc', SUCCEED, 'found', 'abc'),124 ('^abc$', 'abcc', FAIL),125 ('^abc', 'abcc', SUCCEED, 'found', 'abc'),126 ('^abc$', 'aabc', FAIL),127 ('abc$', 'aabc', SUCCEED, 'found', 'abc'),128 ('^', 'abc', SUCCEED, 'found+"-"', '-'),129 ('$', 'abc', SUCCEED, 'found+"-"', '-'),130 ('a.c', 'abc', SUCCEED, 'found', 'abc'),131 ('a.c', 'axc', SUCCEED, 'found', 'axc'),132 ('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'),133 ('a.*c', 'axyzd', FAIL),134 ('a[bc]d', 'abc', FAIL),135 ('a[bc]d', 'abd', SUCCEED, 'found', 'abd'),136 ('a[b-d]e', 'abd', FAIL),137 ('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'),138 ('a[b-d]', 'aac', SUCCEED, 'found', 'ac'),139 ('a[-b]', 'a-', SUCCEED, 'found', 'a-'),140 ('a[\\-b]', 'a-', SUCCEED, 'found', 'a-'),141 ('a[b-]', 'a-', SYNTAX_ERROR),142 ('a[]b', '-', SYNTAX_ERROR),143 ('a[', '-', SYNTAX_ERROR),144 ('a\\', '-', SYNTAX_ERROR),145 ('abc)', '-', SYNTAX_ERROR),146 ('(abc', '-', SYNTAX_ERROR),147 ('a]', 'a]', SUCCEED, 'found', 'a]'),148 ('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),149 ('a[\]]b', 'a]b', SUCCEED, 'found', 'a]b'),150 ('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),151 ('a[^bc]d', 'abd', FAIL),152 ('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),153 ('a[^-b]c', 'a-c', FAIL),154 ('a[^]b]c', 'a]c', FAIL),155 ('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'),156 ('\\ba\\b', 'a-', SUCCEED, '"-"', '-'),157 ('\\ba\\b', '-a', SUCCEED, '"-"', '-'),158 ('\\ba\\b', '-a-', SUCCEED, '"-"', '-'),159 ('\\by\\b', 'xy', FAIL),160 ('\\by\\b', 'yz', FAIL),161 ('\\by\\b', 'xyz', FAIL),162 ('x\\b', 'xyz', FAIL),163 ('x\\B', 'xyz', SUCCEED, '"-"', '-'),164 ('\\Bz', 'xyz', SUCCEED, '"-"', '-'),165 ('z\\B', 'xyz', FAIL),166 ('\\Bx', 'xyz', FAIL),167 ('\\Ba\\B', 'a-', FAIL, '"-"', '-'),168 ('\\Ba\\B', '-a', FAIL, '"-"', '-'),169 ('\\Ba\\B', '-a-', FAIL, '"-"', '-'),170 ('\\By\\B', 'xy', FAIL),171 ('\\By\\B', 'yz', FAIL),172 ('\\By\\b', 'xy', SUCCEED, '"-"', '-'),173 ('\\by\\B', 'yz', SUCCEED, '"-"', '-'),174 ('\\By\\B', 'xyz', SUCCEED, '"-"', '-'),175 ('ab|cd', 'abc', SUCCEED, 'found', 'ab'),176 ('ab|cd', 'abcd', SUCCEED, 'found', 'ab'),177 ('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'),178 ('$b', 'b', FAIL),179 ('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'),180 ('a\\(*b', 'ab', SUCCEED, 'found', 'ab'),181 ('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'),182 ('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'),183 ('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'),184 ('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'),185 ('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'),186 ('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),187 ('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),188 ('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'),189 (')(', '-', SYNTAX_ERROR),190 ('[^ab]*', 'cde', SUCCEED, 'found', 'cde'),191 ('abc', '', FAIL),192 ('a*', '', SUCCEED, 'found', ''),193 ('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'),194 ('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'),195 ('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'),196 ('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'),197 ('ab*', 'xayabbbz', SUCCEED, 'found', 'a'),198 ('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'),199 ('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'),200 ('^(ab|cd)e', 'abcde', FAIL, 'xg1y', 'xy'),201 ('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'),202 ('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'),203 ('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'),204 ('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'),205 ('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),206 ('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),207 ('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'),208 ('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'),209 ('a[bcd]+dcdcde', 'adcdcde', FAIL),210 ('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'),211 ('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'),212 ('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'),213 ('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'),214 ('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),215 ('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'),216 ('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL),217 ('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL),218 ('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),219 ('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'),220 ('multiple words of text', 'uh-uh', FAIL),221 ('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'),222 ('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'),223 ('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'),224 ('[k]', 'ab', FAIL),225 ('a[-]?c', 'ac', SUCCEED, 'found', 'ac'),226 ('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),227 ('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),228 ('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'),229 ('(a+).\\1$', 'aaaaa', SUCCEED, 'found+"-"+g1', 'aaaaa-aa'),230 ('^(a+).\\1$', 'aaaa', FAIL),231 ('(abc)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'),232 ('([a-c]+)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'),233 ('(a)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'),234 ('(a+)\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'),235 ('(a+)+\\1', 'aa', SUCCEED, 'found+"-"+g1', 'aa-a'),236 ('(a).+\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'),237 ('(a)ba*\\1', 'aba', SUCCEED, 'found+"-"+g1', 'aba-a'),238 ('(aa|a)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'),239 ('(a|aa)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'),240 ('(a+)a\\1$', 'aaa', SUCCEED, 'found+"-"+g1', 'aaa-a'),241 ('([abc]*)\\1', 'abcabc', SUCCEED, 'found+"-"+g1', 'abcabc-abc'),242 ('(a)(b)c|ab', 'ab', SUCCEED, 'found+"-"+g1+"-"+g2', 'ab-None-None'),243 ('(a)+x', 'aaax', SUCCEED, 'found+"-"+g1', 'aaax-a'),244 ('([ac])+x', 'aacx', SUCCEED, 'found+"-"+g1', 'aacx-c'),245 ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', SUCCEED, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/'),246 ('([^.]*)\\.([^:]*):[T ]+(.*)', 'track1.title:TBlah blah blah', SUCCEED, 'found+"-"+g1+"-"+g2+"-"+g3', 'track1.title:TBlah blah blah-track1-title-Blah blah blah'),247 ('([^N]*N)+', 'abNNxyzN', SUCCEED, 'found+"-"+g1', 'abNNxyzN-xyzN'),248 ('([^N]*N)+', 'abNNxyz', SUCCEED, 'found+"-"+g1', 'abNN-N'),249 ('([abc]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'abcx-abc'),250 ('([abc]*)x', 'abc', FAIL),251 ('([xyz]*)x', 'abcx', SUCCEED, 'found+"-"+g1', 'x-'),252 ('(a)+b|aac', 'aac', SUCCEED, 'found+"-"+g1', 'aac-None'),253254 # Test symbolic groups255256 ('(?P<i d>aaa)a', 'aaaa', SYNTAX_ERROR),257 ('(?P<id>aaa)a', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aaa'),258 ('(?P<id>aa)(?P=id)', 'aaaa', SUCCEED, 'found+"-"+id', 'aaaa-aa'),259 ('(?P<id>aa)(?P=xd)', 'aaaa', SYNTAX_ERROR),260261 # Test octal escapes/memory references262263 ('\\1', 'a', SYNTAX_ERROR),264 ('\\09', chr(0) + '9', SUCCEED, 'found', chr(0) + '9'),265 ('\\141', 'a', SUCCEED, 'found', 'a'),266 #('(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\\119', 'abcdefghijklk9', SUCCEED, 'found+"-"+g11', 'abcdefghijklk9-k'),267268 # All tests from Perl269270 ('abc', 'abc', SUCCEED, 'found', 'abc'),271 ('abc', 'xbc', FAIL),272 ('abc', 'axc', FAIL),273 ('abc', 'abx', FAIL),274 ('abc', 'xabcy', SUCCEED, 'found', 'abc'),275 ('abc', 'ababc', SUCCEED, 'found', 'abc'),276 ('ab*c', 'abc', SUCCEED, 'found', 'abc'),277 ('ab*bc', 'abc', SUCCEED, 'found', 'abc'),278 ('ab*bc', 'abbc', SUCCEED, 'found', 'abbc'),279 ('ab*bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),280 ('ab{0,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),281 ('ab+bc', 'abbc', SUCCEED, 'found', 'abbc'),282 ('ab+bc', 'abc', FAIL),283 ('ab+bc', 'abq', FAIL),284 ('ab{1,}bc', 'abq', FAIL),285 ('ab+bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),286 ('ab{1,}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),287 ('ab{1,3}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),288 ('ab{3,4}bc', 'abbbbc', SUCCEED, 'found', 'abbbbc'),289 ('ab{4,5}bc', 'abbbbc', FAIL),290 ('ab?bc', 'abbc', SUCCEED, 'found', 'abbc'),291 ('ab?bc', 'abc', SUCCEED, 'found', 'abc'),292 ('ab{0,1}bc', 'abc', SUCCEED, 'found', 'abc'),293 ('ab?bc', 'abbbbc', FAIL),294 ('ab?c', 'abc', SUCCEED, 'found', 'abc'),295 ('ab{0,1}c', 'abc', SUCCEED, 'found', 'abc'),296 ('^abc$', 'abc', SUCCEED, 'found', 'abc'),297 ('^abc$', 'abcc', FAIL),298 ('^abc', 'abcc', SUCCEED, 'found', 'abc'),299 ('^abc$', 'aabc', FAIL),300 ('abc$', 'aabc', SUCCEED, 'found', 'abc'),301 ('^', 'abc', SUCCEED, 'found', ''),302 ('$', 'abc', SUCCEED, 'found', ''),303 ('a.c', 'abc', SUCCEED, 'found', 'abc'),304 ('a.c', 'axc', SUCCEED, 'found', 'axc'),305 ('a.*c', 'axyzc', SUCCEED, 'found', 'axyzc'),306 ('a.*c', 'axyzd', FAIL),307 ('a[bc]d', 'abc', FAIL),308 ('a[bc]d', 'abd', SUCCEED, 'found', 'abd'),309 ('a[b-d]e', 'abd', FAIL),310 ('a[b-d]e', 'ace', SUCCEED, 'found', 'ace'),311 ('a[b-d]', 'aac', SUCCEED, 'found', 'ac'),312 ('a[-b]', 'a-', SUCCEED, 'found', 'a-'),313 ('a[b-]', 'a-', SUCCEED, 'found', 'a-'),314 ('a[b-a]', '-', SYNTAX_ERROR),315 ('a[]b', '-', SYNTAX_ERROR),316 ('a[', '-', SYNTAX_ERROR),317 ('a]', 'a]', SUCCEED, 'found', 'a]'),318 ('a[]]b', 'a]b', SUCCEED, 'found', 'a]b'),319 ('a[^bc]d', 'aed', SUCCEED, 'found', 'aed'),320 ('a[^bc]d', 'abd', FAIL),321 ('a[^-b]c', 'adc', SUCCEED, 'found', 'adc'),322 ('a[^-b]c', 'a-c', FAIL),323 ('a[^]b]c', 'a]c', FAIL),324 ('a[^]b]c', 'adc', SUCCEED, 'found', 'adc'),325 ('ab|cd', 'abc', SUCCEED, 'found', 'ab'),326 ('ab|cd', 'abcd', SUCCEED, 'found', 'ab'),327 ('()ef', 'def', SUCCEED, 'found+"-"+g1', 'ef-'),328 ('*a', '-', SYNTAX_ERROR),329 ('(*)b', '-', SYNTAX_ERROR),330 ('$b', 'b', FAIL),331 ('a\\', '-', SYNTAX_ERROR),332 ('a\\(b', 'a(b', SUCCEED, 'found+"-"+g1', 'a(b-Error'),333 ('a\\(*b', 'ab', SUCCEED, 'found', 'ab'),334 ('a\\(*b', 'a((b', SUCCEED, 'found', 'a((b'),335 ('a\\\\b', 'a\\b', SUCCEED, 'found', 'a\\b'),336 ('abc)', '-', SYNTAX_ERROR),337 ('(abc', '-', SYNTAX_ERROR),338 ('((a))', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'a-a-a'),339 ('(a)b(c)', 'abc', SUCCEED, 'found+"-"+g1+"-"+g2', 'abc-a-c'),340 ('a+b+c', 'aabbabc', SUCCEED, 'found', 'abc'),341 ('a{1,}b{1,}c', 'aabbabc', SUCCEED, 'found', 'abc'),342 ('a**', '-', SYNTAX_ERROR),343 ('a.+?c', 'abcabc', SUCCEED, 'found', 'abc'),344 ('(a+|b)*', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),345 ('(a+|b){0,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),346 ('(a+|b)+', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),347 ('(a+|b){1,}', 'ab', SUCCEED, 'found+"-"+g1', 'ab-b'),348 ('(a+|b)?', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'),349 ('(a+|b){0,1}', 'ab', SUCCEED, 'found+"-"+g1', 'a-a'),350 (')(', '-', SYNTAX_ERROR),351 ('[^ab]*', 'cde', SUCCEED, 'found', 'cde'),352 ('abc', '', FAIL),353 ('a*', '', SUCCEED, 'found', ''),354 ('([abc])*d', 'abbbcd', SUCCEED, 'found+"-"+g1', 'abbbcd-c'),355 ('([abc])*bcd', 'abcd', SUCCEED, 'found+"-"+g1', 'abcd-a'),356 ('a|b|c|d|e', 'e', SUCCEED, 'found', 'e'),357 ('(a|b|c|d|e)f', 'ef', SUCCEED, 'found+"-"+g1', 'ef-e'),358 ('abcd*efg', 'abcdefg', SUCCEED, 'found', 'abcdefg'),359 ('ab*', 'xabyabbbz', SUCCEED, 'found', 'ab'),360 ('ab*', 'xayabbbz', SUCCEED, 'found', 'a'),361 ('(ab|cd)e', 'abcde', SUCCEED, 'found+"-"+g1', 'cde-cd'),362 ('[abhgefdc]ij', 'hij', SUCCEED, 'found', 'hij'),363 ('^(ab|cd)e', 'abcde', FAIL),364 ('(abc|)ef', 'abcdef', SUCCEED, 'found+"-"+g1', 'ef-'),365 ('(a|b)c*d', 'abcd', SUCCEED, 'found+"-"+g1', 'bcd-b'),366 ('(ab|ab*)bc', 'abc', SUCCEED, 'found+"-"+g1', 'abc-a'),367 ('a([bc]*)c*', 'abc', SUCCEED, 'found+"-"+g1', 'abc-bc'),368 ('a([bc]*)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),369 ('a([bc]+)(c*d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-bc-d'),370 ('a([bc]*)(c+d)', 'abcd', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcd-b-cd'),371 ('a[bcd]*dcdcde', 'adcdcde', SUCCEED, 'found', 'adcdcde'),372 ('a[bcd]+dcdcde', 'adcdcde', FAIL),373 ('(ab|a)b*c', 'abc', SUCCEED, 'found+"-"+g1', 'abc-ab'),374 ('((a)(b)c)(d)', 'abcd', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'abc-a-b-d'),375 ('[a-zA-Z_][a-zA-Z0-9_]*', 'alpha', SUCCEED, 'found', 'alpha'),376 ('^a(bc+|b[eh])g|.h$', 'abh', SUCCEED, 'found+"-"+g1', 'bh-None'),377 ('(bc+d$|ef*g.|h?i(j|k))', 'effgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),378 ('(bc+d$|ef*g.|h?i(j|k))', 'ij', SUCCEED, 'found+"-"+g1+"-"+g2', 'ij-ij-j'),379 ('(bc+d$|ef*g.|h?i(j|k))', 'effg', FAIL),380 ('(bc+d$|ef*g.|h?i(j|k))', 'bcdd', FAIL),381 ('(bc+d$|ef*g.|h?i(j|k))', 'reffgz', SUCCEED, 'found+"-"+g1+"-"+g2', 'effgz-effgz-None'),382 ('((((((((((a))))))))))', 'a', SUCCEED, 'g10', 'a'),383 ('((((((((((a))))))))))\\10', 'aa', SUCCEED, 'found', 'aa'),384# Python does not have the same rules for \\41 so this is a syntax error385# ('((((((((((a))))))))))\\41', 'aa', FAIL),386# ('((((((((((a))))))))))\\41', 'a!', SUCCEED, 'found', 'a!'),387 ('((((((((((a))))))))))\\41', '', SYNTAX_ERROR),388 ('(?i)((((((((((a))))))))))\\41', '', SYNTAX_ERROR),389 ('(((((((((a)))))))))', 'a', SUCCEED, 'found', 'a'),390 ('multiple words of text', 'uh-uh', FAIL),391 ('multiple words', 'multiple words, yeah', SUCCEED, 'found', 'multiple words'),392 ('(.*)c(.*)', 'abcde', SUCCEED, 'found+"-"+g1+"-"+g2', 'abcde-ab-de'),393 ('\\((.*), (.*)\\)', '(a, b)', SUCCEED, 'g2+"-"+g1', 'b-a'),394 ('[k]', 'ab', FAIL),395 ('a[-]?c', 'ac', SUCCEED, 'found', 'ac'),396 ('(abc)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),397 ('([a-c]*)\\1', 'abcabc', SUCCEED, 'g1', 'abc'),398 ('(?i)abc', 'ABC', SUCCEED, 'found', 'ABC'),399 ('(?i)abc', 'XBC', FAIL),400 ('(?i)abc', 'AXC', FAIL),401 ('(?i)abc', 'ABX', FAIL),402 ('(?i)abc', 'XABCY', SUCCEED, 'found', 'ABC'),403 ('(?i)abc', 'ABABC', SUCCEED, 'found', 'ABC'),404 ('(?i)ab*c', 'ABC', SUCCEED, 'found', 'ABC'),405 ('(?i)ab*bc', 'ABC', SUCCEED, 'found', 'ABC'),406 ('(?i)ab*bc', 'ABBC', SUCCEED, 'found', 'ABBC'),407 ('(?i)ab*?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),408 ('(?i)ab{0,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),409 ('(?i)ab+?bc', 'ABBC', SUCCEED, 'found', 'ABBC'),410 ('(?i)ab+bc', 'ABC', FAIL),411 ('(?i)ab+bc', 'ABQ', FAIL),412 ('(?i)ab{1,}bc', 'ABQ', FAIL),413 ('(?i)ab+bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),414 ('(?i)ab{1,}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),415 ('(?i)ab{1,3}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),416 ('(?i)ab{3,4}?bc', 'ABBBBC', SUCCEED, 'found', 'ABBBBC'),417 ('(?i)ab{4,5}?bc', 'ABBBBC', FAIL),418 ('(?i)ab??bc', 'ABBC', SUCCEED, 'found', 'ABBC'),419 ('(?i)ab??bc', 'ABC', SUCCEED, 'found', 'ABC'),420 ('(?i)ab{0,1}?bc', 'ABC', SUCCEED, 'found', 'ABC'),421 ('(?i)ab??bc', 'ABBBBC', FAIL),422 ('(?i)ab??c', 'ABC', SUCCEED, 'found', 'ABC'),423 ('(?i)ab{0,1}?c', 'ABC', SUCCEED, 'found', 'ABC'),424 ('(?i)^abc$', 'ABC', SUCCEED, 'found', 'ABC'),425 ('(?i)^abc$', 'ABCC', FAIL),426 ('(?i)^abc', 'ABCC', SUCCEED, 'found', 'ABC'),427 ('(?i)^abc$', 'AABC', FAIL),428 ('(?i)abc$', 'AABC', SUCCEED, 'found', 'ABC'),429 ('(?i)^', 'ABC', SUCCEED, 'found', ''),430 ('(?i)$', 'ABC', SUCCEED, 'found', ''),431 ('(?i)a.c', 'ABC', SUCCEED, 'found', 'ABC'),432 ('(?i)a.c', 'AXC', SUCCEED, 'found', 'AXC'),433 ('(?i)a.*?c', 'AXYZC', SUCCEED, 'found', 'AXYZC'),434 ('(?i)a.*c', 'AXYZD', FAIL),435 ('(?i)a[bc]d', 'ABC', FAIL),436 ('(?i)a[bc]d', 'ABD', SUCCEED, 'found', 'ABD'),437 ('(?i)a[b-d]e', 'ABD', FAIL),438 ('(?i)a[b-d]e', 'ACE', SUCCEED, 'found', 'ACE'),439 ('(?i)a[b-d]', 'AAC', SUCCEED, 'found', 'AC'),440 ('(?i)a[-b]', 'A-', SUCCEED, 'found', 'A-'),441 ('(?i)a[b-]', 'A-', SUCCEED, 'found', 'A-'),442 ('(?i)a[b-a]', '-', SYNTAX_ERROR),443 ('(?i)a[]b', '-', SYNTAX_ERROR),444 ('(?i)a[', '-', SYNTAX_ERROR),445 ('(?i)a]', 'A]', SUCCEED, 'found', 'A]'),446 ('(?i)a[]]b', 'A]B', SUCCEED, 'found', 'A]B'),447 ('(?i)a[^bc]d', 'AED', SUCCEED, 'found', 'AED'),448 ('(?i)a[^bc]d', 'ABD', FAIL),449 ('(?i)a[^-b]c', 'ADC', SUCCEED, 'found', 'ADC'),450 ('(?i)a[^-b]c', 'A-C', FAIL),451 ('(?i)a[^]b]c', 'A]C', FAIL),452 ('(?i)a[^]b]c', 'ADC', SUCCEED, 'found', 'ADC'),453 ('(?i)ab|cd', 'ABC', SUCCEED, 'found', 'AB'),454 ('(?i)ab|cd', 'ABCD', SUCCEED, 'found', 'AB'),455 ('(?i)()ef', 'DEF', SUCCEED, 'found+"-"+g1', 'EF-'),456 ('(?i)*a', '-', SYNTAX_ERROR),457 ('(?i)(*)b', '-', SYNTAX_ERROR),458 ('(?i)$b', 'B', FAIL),459 ('(?i)a\\', '-', SYNTAX_ERROR),460 ('(?i)a\\(b', 'A(B', SUCCEED, 'found+"-"+g1', 'A(B-Error'),461 ('(?i)a\\(*b', 'AB', SUCCEED, 'found', 'AB'),462 ('(?i)a\\(*b', 'A((B', SUCCEED, 'found', 'A((B'),463 ('(?i)a\\\\b', 'A\\B', SUCCEED, 'found', 'A\\B'),464 ('(?i)abc)', '-', SYNTAX_ERROR),465 ('(?i)(abc', '-', SYNTAX_ERROR),466 ('(?i)((a))', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'A-A-A'),467 ('(?i)(a)b(c)', 'ABC', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABC-A-C'),468 ('(?i)a+b+c', 'AABBABC', SUCCEED, 'found', 'ABC'),469 ('(?i)a{1,}b{1,}c', 'AABBABC', SUCCEED, 'found', 'ABC'),470 ('(?i)a**', '-', SYNTAX_ERROR),471 ('(?i)a.+?c', 'ABCABC', SUCCEED, 'found', 'ABC'),472 ('(?i)a.*?c', 'ABCABC', SUCCEED, 'found', 'ABC'),473 ('(?i)a.{0,5}?c', 'ABCABC', SUCCEED, 'found', 'ABC'),474 ('(?i)(a+|b)*', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),475 ('(?i)(a+|b){0,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),476 ('(?i)(a+|b)+', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),477 ('(?i)(a+|b){1,}', 'AB', SUCCEED, 'found+"-"+g1', 'AB-B'),478 ('(?i)(a+|b)?', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'),479 ('(?i)(a+|b){0,1}', 'AB', SUCCEED, 'found+"-"+g1', 'A-A'),480 ('(?i)(a+|b){0,1}?', 'AB', SUCCEED, 'found+"-"+g1', '-None'),481 ('(?i))(', '-', SYNTAX_ERROR),482 ('(?i)[^ab]*', 'CDE', SUCCEED, 'found', 'CDE'),483 ('(?i)abc', '', FAIL),484 ('(?i)a*', '', SUCCEED, 'found', ''),485 ('(?i)([abc])*d', 'ABBBCD', SUCCEED, 'found+"-"+g1', 'ABBBCD-C'),486 ('(?i)([abc])*bcd', 'ABCD', SUCCEED, 'found+"-"+g1', 'ABCD-A'),487 ('(?i)a|b|c|d|e', 'E', SUCCEED, 'found', 'E'),488 ('(?i)(a|b|c|d|e)f', 'EF', SUCCEED, 'found+"-"+g1', 'EF-E'),489 ('(?i)abcd*efg', 'ABCDEFG', SUCCEED, 'found', 'ABCDEFG'),490 ('(?i)ab*', 'XABYABBBZ', SUCCEED, 'found', 'AB'),491 ('(?i)ab*', 'XAYABBBZ', SUCCEED, 'found', 'A'),492 ('(?i)(ab|cd)e', 'ABCDE', SUCCEED, 'found+"-"+g1', 'CDE-CD'),493 ('(?i)[abhgefdc]ij', 'HIJ', SUCCEED, 'found', 'HIJ'),494 ('(?i)^(ab|cd)e', 'ABCDE', FAIL),495 ('(?i)(abc|)ef', 'ABCDEF', SUCCEED, 'found+"-"+g1', 'EF-'),496 ('(?i)(a|b)c*d', 'ABCD', SUCCEED, 'found+"-"+g1', 'BCD-B'),497 ('(?i)(ab|ab*)bc', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-A'),498 ('(?i)a([bc]*)c*', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-BC'),499 ('(?i)a([bc]*)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'),500 ('(?i)a([bc]+)(c*d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-BC-D'),501 ('(?i)a([bc]*)(c+d)', 'ABCD', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCD-B-CD'),502 ('(?i)a[bcd]*dcdcde', 'ADCDCDE', SUCCEED, 'found', 'ADCDCDE'),503 ('(?i)a[bcd]+dcdcde', 'ADCDCDE', FAIL),504 ('(?i)(ab|a)b*c', 'ABC', SUCCEED, 'found+"-"+g1', 'ABC-AB'),505 ('(?i)((a)(b)c)(d)', 'ABCD', SUCCEED, 'g1+"-"+g2+"-"+g3+"-"+g4', 'ABC-A-B-D'),506 ('(?i)[a-zA-Z_][a-zA-Z0-9_]*', 'ALPHA', SUCCEED, 'found', 'ALPHA'),507 ('(?i)^a(bc+|b[eh])g|.h$', 'ABH', SUCCEED, 'found+"-"+g1', 'BH-None'),508 ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'),509 ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'IJ', SUCCEED, 'found+"-"+g1+"-"+g2', 'IJ-IJ-J'),510 ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'EFFG', FAIL),511 ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'BCDD', FAIL),512 ('(?i)(bc+d$|ef*g.|h?i(j|k))', 'REFFGZ', SUCCEED, 'found+"-"+g1+"-"+g2', 'EFFGZ-EFFGZ-None'),513 ('(?i)((((((((((a))))))))))', 'A', SUCCEED, 'g10', 'A'),514 ('(?i)((((((((((a))))))))))\\10', 'AA', SUCCEED, 'found', 'AA'),515 #('(?i)((((((((((a))))))))))\\41', 'AA', FAIL),516 #('(?i)((((((((((a))))))))))\\41', 'A!', SUCCEED, 'found', 'A!'),517 ('(?i)(((((((((a)))))))))', 'A', SUCCEED, 'found', 'A'),518 ('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))', 'A', SUCCEED, 'g1', 'A'),519 ('(?i)(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))', 'C', SUCCEED, 'g1', 'C'),520 ('(?i)multiple words of text', 'UH-UH', FAIL),521 ('(?i)multiple words', 'MULTIPLE WORDS, YEAH', SUCCEED, 'found', 'MULTIPLE WORDS'),522 ('(?i)(.*)c(.*)', 'ABCDE', SUCCEED, 'found+"-"+g1+"-"+g2', 'ABCDE-AB-DE'),523 ('(?i)\\((.*), (.*)\\)', '(A, B)', SUCCEED, 'g2+"-"+g1', 'B-A'),524 ('(?i)[k]', 'AB', FAIL),525# ('(?i)abcd', 'ABCD', SUCCEED, 'found+"-"+\\found+"-"+\\\\found', 'ABCD-$&-\\ABCD'),526# ('(?i)a(bc)d', 'ABCD', SUCCEED, 'g1+"-"+\\g1+"-"+\\\\g1', 'BC-$1-\\BC'),527 ('(?i)a[-]?c', 'AC', SUCCEED, 'found', 'AC'),528 ('(?i)(abc)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'),529 ('(?i)([a-c]*)\\1', 'ABCABC', SUCCEED, 'g1', 'ABC'),530 ('a(?!b).', 'abad', SUCCEED, 'found', 'ad'),531 ('a(?=d).', 'abad', SUCCEED, 'found', 'ad'),532 ('a(?=c|d).', 'abad', SUCCEED, 'found', 'ad'),533 ('a(?:b|c|d)(.)', 'ace', SUCCEED, 'g1', 'e'),534 ('a(?:b|c|d)*(.)', 'ace', SUCCEED, 'g1', 'e'),535 ('a(?:b|c|d)+?(.)', 'ace', SUCCEED, 'g1', 'e'),536 ('a(?:b|(c|e){1,2}?|d)+?(.)', 'ace', SUCCEED, 'g1 + g2', 'ce'),537 ('^(.+)?B', 'AB', SUCCEED, 'g1', 'A'),538539 # Comments using the (?#...) syntax540541 ('w(?# comment', 'w', SYNTAX_ERROR),542 ('w(?# comment 1)xy(?# comment 2)z', 'wxyz', SUCCEED, 'found', 'wxyz'),543544 # Check odd placement of embedded pattern modifiers545546 ('w(?i)', 'W', SYNTAX_ERROR),547548 # Comments using the x embedded pattern modifier549550 ("""(?x)w# comment 1551 x y552 # comment 2553 z""", 'wxyz', SUCCEED, 'found', 'wxyz'),554555 # using the m embedded pattern modifier556557 #('^abc', """jkl558#abc559#xyz""", FAIL),560 ('(?m)^abc', """jkl561abc562xyz""", SUCCEED, 'found', 'abc'),563564 ('(?m)abc$', """jkl565xyzabc566123""", SUCCEED, 'found', 'abc'),567568 # using the s embedded pattern modifier569570 ('a.b', 'a\nb', FAIL),571 ('(?s)a.b', 'a\nb', SUCCEED, 'found', 'a\nb'),572573 # test \w, etc. both inside and outside character classes574575 ('\\w+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'),576 ('[\\w]+', '--ab_cd0123--', SUCCEED, 'found', 'ab_cd0123'),577 ('\\D+', '1234abc5678', SUCCEED, 'found', 'abc'),578 ('[\\D]+', '1234abc5678', SUCCEED, 'found', 'abc'),579 ('[\\da-fA-F]+', '123abc', SUCCEED, 'found', '123abc'),580 ('[\\d-x]', '-', SYNTAX_ERROR),581 (r'([\s]*)([\S]*)([\s]*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '),582 (r'(\s*)(\S*)(\s*)', ' testing!1972', SUCCEED, 'g3+g2+g1', 'testing!1972 '),583584 (r'\xff', '\377', SUCCEED, 'found', chr(255)),585 #(r'\x00ff', '\377', SUCCEED, 'found', chr(255)),586 #(r'\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'),587 ('\t\n\v\r\f\a\g', '\t\n\v\r\f\ag', SUCCEED, 'found', '\t\n\v\r\f\ag'),588 #(r'\t\n\v\r\f\a', '\t\n\v\r\f\a', SUCCEED, 'found', chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)),589 #(r'[\t][\n][\v][\r][\f][\b]', '\t\n\v\r\f\b', SUCCEED, 'found', '\t\n\v\r\f\b'), ...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1var express = require("express"),2 app =express(),3 bodyparser =require("body-parser"),4 mongoose =require("mongoose"),5 multer =require("multer"),6 methodOverride =require("method-override"),7 passport =require("passport"),8 Project =require("./models/project"),9 User =require("./models/user"),10 Appliedproject =require("./models/appliedProject"),11 middleware =require("./middleware"),12 session =require("express-session"),13 multer = require('multer'), 14 fs = require('fs'),15 path = require('path');1617 18 // SET STORAGE19 var storage = multer.diskStorage({20 destination: function (req, file, cb) {21 cb(null, 'public/uploads') //null is the error field and uploads is the folder name where pictures will be stored22 },23 filename: function (req, file, cb) {24 cb(null, file.fieldname + '-' + Date.now()+path.extname(file.originalname)) //fieldname is the name given to the upload input box in the html file and path is used to get the file extension name25 }26 }) 27 var upload = multer({ storage: storage })28293031app.use(bodyparser.urlencoded({extended:true}));32app.use('/public',express.static('public'));33app.use(methodOverride("_method"));343536app.set("view engine","ejs");373839mongoose.connect("mongodb://localhost:27017/ProjectPortal", { useNewUrlParser: true,useUnifiedTopology: true,useFindAndModify:false});404142//Setting up passport43app.use(session({44 secret: "Its our secret.",45 resave: false,46 saveUninitialized: false47}));4849app.use(passport.initialize());50app.use(passport.session());51passport.use(User.createStrategy());52passport.serializeUser(User.serializeUser());53passport.deserializeUser(User.deserializeUser());54555657const { POINT_CONVERSION_COMPRESSED } = require("constants");58const e = require("express");59const { isLoggedIn } = require("./middleware");60var indexRoutes = require("./routes/index");6162app.use(indexRoutes);636465app.get("/projects",function(req,res){66 Project.find({},function(err,allProjects){67 if(err){68 console.log(err);69 }70 else{71 res.render("project",{user:req.user,projects:allProjects});72 }73 });7475});767778app.get("/projects/new",middleware.isLoggedIn,function(req,res){79 res.render("new",{user:req.user});80});81app.post("/projects",function(req,res){82 const title = req.body.title;83 const description = req.body.description;84 const technology = req.body.technology;85 const max = req.body.members;86 var user = {87 id:req.user,88 username:req.user.email89 }90 const newproject = new Project({91 title:title,92 descrip:description,93 technologies:technology,94 max:max,95 need:max,96 owner:user97 });9899 100 newproject.save(function(err){101 if(!err){102 req.user.projects.push(newproject._id);103 req.user.save();104 res.redirect("/projects");105 }106 });107})108109app.get("/projects/:id",function(req,res){110 const projectId = req.params.id;111 Project.findById(projectId,function(err,foundProject){112 if(err){113 console.log(err);114 }115 else{116 res.render("show",{project:foundProject,user:req.user});117 }118 })119120121});122123124app.get("/userprofile/editproject",middleware.isLoggedIn,function(req,res){125 User.findById(req.user.id).populate("projects").exec(function(err,foundUser){126 if(err){127 console.log(err);128 }129 else{130 res.render("editproject",{userprojects:foundUser,user:req.user});131132 }133 });134 135});136137app.get("/userprofile",middleware.isLoggedIn,function(req,res){138 Appliedproject.find({}).remove().exec();139 User.findById(req.user._id,function(err,foundUser){140 141142 143 console.log(foundUser.projects);144 User.find({appliedProjects:{$in:foundUser.projects}},function(err,foundApplications){145 if(err){146 console.log(err);147 }148 else{149 console.log(foundApplications);150 151 152 foundApplications.forEach(function(foundApplication){153 console.log(foundApplication.appliedProjects);154 foundApplication.appliedProjects.forEach(function(project){155 156 157 Project.findById(project,function(err,foundProject){158 if(err){159 console.log(err);160 }161 else { 162163 User.findById(foundProject.owner.id,function(err,foundOwner){164 if(err){165 console.log(err);166 }167 else{168 //console.log(foundOwner.username);169 if(foundOwner.username === req.user.username){170 console.log(foundProject.title,foundApplication.email);171 172 let appliedProjectss = new Appliedproject(173 { 174 id:foundProject._id,175 title:foundProject.title,176 name:foundApplication.email,177 userId:foundApplication._id178 }179 );180 appliedProjectss.save();181 182 183 184 }185 186 }187 188 189 190 191 })192 193 194 }195 196 })197 })198 });199 200 }201 })202203 204205 });206 res.render("profile",{user:req.user});207});208209210app.get("/userprofile/:id",function(req,res){211 var profileuser = req.params.id;212 User.findById(profileuser,function(err,foundUser){213 if(err){214 console.log(err);215 }216 else217 {218 219 res.render("userprofile",{puser:foundUser,user:req.user});220 }221 })222 223 });224225226 app.get("/editprofile",middleware.isLoggedIn,function(req,res){227 res.render("editprofile",{user:req.user,puser:req.user});228})229230231app.put("/userprofile",middleware.isLoggedIn, upload.single('myImage'),function(req,res){232 var img = fs.readFileSync(req.file.path);233 var encode_image = img.toString('base64'); 234 var finalImg = { // Define a JSONobject for the image attributes for saving to database235 contentType: req.file.mimetype,236 path:req.file.path,237 image: new Buffer(encode_image, 'base64')238 };239 var userData = {240 username: req.body.username,241 about: req.body.about, 242 img:finalImg,243 email:req.body.email,244 institute:req.body.institute, 245 language:req.body.language,246 github:req.body.github,247 linkedIn:req.body.linkedIn248249 }250 User.findByIdAndUpdate(req.user.id,userData,function(err,updateUser){251 if(err){252 console.log(err);253 res.redirect("/userprofile");254 }255 else{256 console.log(userData);257 console.log(updateUser);258 res.redirect("/userprofile");259 }260 })261});262263app.get("/projects/editproject/:id",middleware.isLoggedIn,function(req,res){264 const projectId = req.params.id;265 Project.findById(projectId,function(err,foundProject){266 if(err){267 console.log(err);268 }269 else{270 res.render("newedit",{user:req.user,project:foundProject});271 }272 })273274});275276app.put("/projects/editproject/:id",middleware.isLoggedIn,function(req,res){277 const projectId = req.params.id278 const title = req.body.title;279 const description = req.body.description;280 const technology = req.body.technology;281 const max = req.body.members;282 var user = {283 id:req.user,284 username:req.user.email285 }286 const updatedProject = {287 title:title,288 descrip:description,289 technologies:technology,290 max:max,291 need:max,292 owner:user293 };294 295 Project.findByIdAndUpdate(projectId,updatedProject,function(err,updated){296 if(err){297 console.log(err);298 res.redirect("/editproject/editproject");299 }300 else{301 console.log(updatedProject);302 console.log(updated);303 res.redirect("/userprofile/editproject");304 }305 })306});307308app.delete("/projects/editproject/delete/:id",middleware.isLoggedIn,function(req,res){309310 Project.findById(req.params.id,function(err,foundProject){311 if(err){312 console.log(err);313314 }315 else{316 User.findById(foundProject.owner.id,function(err,foundOwner){317 console.log(foundOwner.username);318 console.log(req.user.username);319 if(req.user.username === foundOwner.username){320 Project.findByIdAndRemove(req.params.id,function(err,foundProject){321 if(err){322 console.log(err);323 }324 else{325 console.log(foundOwner.projects);326 console.log(foundProject._id);327 328 // User.update({_id:req.user._id},{$pull:{projects:{$in:["5fc481fb447417376853704e"]}} },{multi:true});329 // User.updateOne({_id: req.user._id}, {$pull: { projects: { $in: [foundProject._id] } }})330 const index = foundOwner.projects.indexOf(foundProject._id);331 if (index > -1) {332 var p=foundOwner.projects.splice(index, 1);333 }334 335 console.log(foundOwner.projects);336 foundOwner.save();337 res.redirect("/userprofile/editproject");338 339 }340 })341 }342 })343 344 }345 })346347});348349350351352353 app.get("/showgotrequest",middleware.isLoggedIn,function(req,res){354355356357 358 Appliedproject.find({},function(err,foundappliedprojects){359 if(err){360 console.log(err);361 }362 else{363 console.log(foundappliedprojects);364 res.render("gotRequests",{user:req.user,applications:foundappliedprojects});365 366 }367 })368 })369 370 371372app.post("/showgotrequest/:id/:userId/accept",function(req,res){373 let flag1=0;374 const projectId = req.params.id;375 const userId = req.params.userId;376 Project.findById(projectId,function(err,foundProject){377 if(err){378 console.log(err);379 }380 else{381 foundProject.team.forEach(function(member){382 if(member.equals(userId)){383 flag1=1;384 }385 })386 if(flag1===0){387 foundProject.team.push(userId);388 foundProject.need=foundProject.need-1;389 foundProject.save();390 }391 }392 })393 res.redirect("/showgotrequest");394})395app.post("/showgotrequest/:id/:userId/reject",function(req,res){396 const projectId = req.params.id;397 const userId = req.params.userId;398 Project.findById(projectId,function(err,foundProject){399 if(err){400 console.log(err);401 }402 else{403 404 const index = foundProject.team.indexOf(userId);405 if (index > -1) {406 var p=foundProject.team.splice(index, 1);407 foundProject.need=foundProject.need+1;408 }409 410 foundProject.save();411 }412 })413 res.redirect("/showgotrequest");414 415})416417418419420app.get("/request",middleware.isLoggedIn,function(req,res){421 422 User.findById(req.user._id,function(err,foundUser){423 if(err){424 console.log(err);425 }426 else{427 console.log(foundUser.appliedProjects);428 Project.find({_id:{$in:foundUser.appliedProjects}},function(err,foundProjects){429 console.log(foundProjects);430 if(err){431 console.log(err);432 }433 else{434 res.render("requests",{user:req.user,appliedprojects:foundProjects});435 }436 })437 438 }439 })440 441});442443app.post("/request/:id",middleware.isLoggedIn,function(req,res){444445 const projectId = req.params.id;446 User.findById(req.user._id,function(err,foundUser){447 if(err){448 console.log(err);449 res.redirect("/projects");450 }451 else{452 var flag=0;453 foundUser.appliedProjects.forEach(function(project){454 console.log(projectId);455 console.log(project);456 if(project.equals(projectId)){457 flag=1;458 459 }460 461 })462 console.log(flag);463 if(flag === 0){464 Project.findById(projectId,function(err,found){465 if(err){466 console.log(err);467 }468 else{469 User.findById(found.owner.id,function(err,foundOwner){470 if(err){471 console.log(err);472 }473 else{474 if(foundOwner.username != req.user.username)475 {476 console.log(foundOwner.username);477 console.log(req.user.username);478 foundUser.appliedProjects.push(projectId);479 foundUser.save();480 }481 }482 })483 }484 })485 486 }487 res.redirect("/projects");488 489 490 }491 492 })493})494495app.post("/request/:id/delete",middleware.isLoggedIn,function(req,res){496 const projectId = req.params.id;497 498 Project.findById(projectId,function(err,foundProject){499 if(err){500 console.log(err);501 }502 else{503 504 const index = foundProject.team.indexOf(req.user._id);505 if (index > -1) {506 var p=foundProject.team.splice(index, 1);507 foundProject.need=foundProject.need+1;508 }509 510 foundProject.save();511 }512 })513514 User.findById({_id:req.user._id},function(err,foundUser){515 if(err){516 console.log(err);517518 }519 else{520 const index = foundUser.appliedProjects.indexOf(projectId);521 if (index > -1) {522 var p=foundUser.appliedProjects.splice(index, 1);523 }524 525 foundUser.save();526 res.redirect("/request");527 }528 })529530})531532533let port=process.env.PORT;534if(port==null||port==""){535 port=9000;536}537app.listen(port, function () {538 console.log("Server started successfully at port 9000"); ...

Full Screen

Full Screen

class.js

Source:class.js Github

copy

Full Screen

1class Grass {2 constructor(x, y) {3 this.x = x;4 this.y = y;5 this.multiplay = 0;6 this.directions = [7 [this.x - 1, this.y - 1],8 [this.x, this.y - 1],9 [this.x + 1, this.y - 1],10 [this.x - 1, this.y],11 [this.x + 1, this.y],12 [this.x - 1, this.y + 1],13 [this.x, this.y + 1],14 [this.x + 1, this.y + 1]15 ];16 }17 search(char) {18 let found = [];19 for (let i in this.directions) {20 let x = this.directions[i][0];21 let y = this.directions[i][1];22 if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {23 if (matrix[y][x] == char) {24 found.push(this.directions[i])25 }26 }27 }28 return found;29 }30 mul() {31 let found = this.search(0);32 var foundRand = random(found);33 this.multiplay++;34 if (this.multiplay >= 3 && foundRand) {35 let x = foundRand[0];36 let y = foundRand[1];37 matrix[y][x] = 138 let gr1 = new Grass(x, y);39 grassArr.push(gr1);40 this.multiplay = 041 }42 }43}44class GrassEater {45 constructor(x, y) {46 this.x = x;47 this.y = y;48 this.energy = 20;49 this.directions = [];50 }51 getNewCoordinates() {52 this.directions = [53 [this.x - 1, this.y - 1],54 [this.x, this.y - 1],55 [this.x + 1, this.y - 1],56 [this.x - 1, this.y],57 [this.x + 1, this.y],58 [this.x - 1, this.y + 1],59 [this.x, this.y + 1],60 [this.x + 1, this.y + 1]61 ];62 }63 search(char) {64 this.getNewCoordinates();65 let found = [];66 for (let i in this.directions) {67 let x = this.directions[i][0];68 let y = this.directions[i][1];69 if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {70 if (matrix[y][x] == char) {71 found.push(this.directions[i])72 }73 }74 }75 return found;76 }77 mul() {78 let found = this.search(0);79 var foundRand = random(found);80 if (foundRand) {81 let x = foundRand[0];82 let y = foundRand[1];83 matrix[y][x] = 284 let newGrassEat = new GrassEater(x, y);85 grassEatArr.push(newGrassEat);86 this.energy = 287 }88 }89 move() {90 this.energy--91 let found = this.search(0);92 var foundRand = random(found);93 if (foundRand && this.energy >= 0) {94 let x = foundRand[0];95 let y = foundRand[1];96 matrix[y][x] = matrix[this.y][this.x]97 matrix[this.y][this.x] = 098 this.x = x99 this.y = y100 } else {101 this.die()102 }103 }104 eat() {105 let found = this.search(1);106 var foundRand = random(found);107 let found1 = this.search(4);108 let found1Rand = random(found1);109 let found2 = this.search(5)110 let found2Rand = random(found2)111 if (found1Rand) {112 let x = found1Rand[0];113 let y = found1Rand[1];114 matrix[y][x] = matrix[this.y][this.x]115 matrix[this.y][this.x] = 0116 this.x = x117 this.y = y118 this.mul()119 for (var i in mulBoostArr) {120 if (x == mulBoostArr[i].x && y == mulBoostArr[i].y) {121 mulBoostArr.splice(i, 1);122 break;123 }124 }125 }126 else if (found2Rand) {127 let x = found2Rand[0];128 let y = found2Rand[1];129 matrix[y][x] = 3130 matrix[this.y][this.x] = 0131 this.x = x132 this.y = y133 this.die()134 for (let i in virusArr) {135 if (x == virusArr[i].x && y == virusArr[i].y) {136 virusArr.splice(i, 1);137 break;138 }139 }140 }141 else if (foundRand) {142 this.energy++143 let x = foundRand[0];144 let y = foundRand[1];145 matrix[y][x] = matrix[this.y][this.x]146 matrix[this.y][this.x] = 0147 this.x = x148 this.y = y149 for (var i in grassArr) {150 if (x == grassArr[i].x && y == grassArr[i].y) {151 grassArr.splice(i, 1);152 break;153 }154 }155 if (this.energy >= 20) {156 this.mul()157 }158 }159 else {160 this.move()161 }162 }163 die() {164 matrix[this.y][this.x] = 0165 for (var i in grassEatArr) {166 if (this.x == grassEatArr[i].x && this.y == grassEatArr[i].y) {167 grassEatArr.splice(i, 1);168 break;169 }170 }171 }172}173class Predator {174 constructor(x, y) {175 this.x = x;176 this.y = y;177 this.energy = 8;178 this.directions = [];179 }180 getNewCoordinates() {181 this.directions = [182 [this.x - 1, this.y - 1],183 [this.x, this.y - 1],184 [this.x + 1, this.y - 1],185 [this.x - 1, this.y],186 [this.x + 1, this.y],187 [this.x - 1, this.y + 1],188 [this.x, this.y + 1],189 [this.x + 1, this.y + 1]190 ];191 }192 search(char) {193 this.getNewCoordinates();194 let found = [];195 for (let i in this.directions) {196 let x = this.directions[i][0];197 let y = this.directions[i][1];198 if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {199 if (matrix[y][x] == char) {200 found.push(this.directions[i])201 }202 }203 }204 return found;205 }206 move() {207 this.energy--208 let found = this.search(0);209 var foundRand = random(found);210 if (foundRand && this.energy >= 0) {211 let x = foundRand[0];212 let y = foundRand[1];213 matrix[y][x] = matrix[this.y][this.x]214 matrix[this.y][this.x] = 0215 this.x = x216 this.y = y217 } else {218 this.die()219 }220 }221 mul() {222 let found = this.search(0);223 var foundRand = random(found);224 if (foundRand) {225 let x = foundRand[0];226 let y = foundRand[1];227 matrix[y][x] = 3228 let pred = new Predator(x, y);229 predatorArr.push(pred);230 this.energy = 3231 }232 }233 eat() {234 let found = this.search(1);235 var foundRand = random(found);236 let found1 = this.search(2)237 let foundRand1 = random(found1)238 let found2 = this.search(4)239 let foundRand2 = random(found2)240 let found3 = this.search(5)241 let foundRand3 = random(found3)242 if (foundRand1) {243 this.energy++244 let x = foundRand1[0];245 let y = foundRand1[1];246 matrix[y][x] = 3247 matrix[this.y][this.x] = 0248 this.x = x249 this.y = y250 for (var i in grassEatArr) {251 if (x == grassEatArr[i].x && y == grassEatArr[i].y) {252 grassEatArr.splice(i, 1);253 break;254 }255 }256 if (this.energy >= 40) {257 this.mul();258 }259 }260 else if (foundRand2) {261 let x = foundRand2[0];262 let y = foundRand2[1];263 matrix[y][x] = 3264 matrix[this.y][this.x] = 0265 this.x = x266 this.y = y267 this.mul()268 for (let i in mulBoostArr) {269 if (x == mulBoostArr[i].x && y == mulBoostArr[i].y) {270 mulBoostArr.splice(i, 1);271 break;272 }273 }274 }275 else if (foundRand3) {276 let x = foundRand3[0];277 let y = foundRand3[1];278 matrix[y][x] = 3279 matrix[this.y][this.x] = 0280 this.x = x281 this.y = y282 this.die()283 for (let i in virusArr) {284 if (x == virusArr[i].x && y == virusArr[i].y) {285 virusArr.splice(i, 1);286 break;287 }288 }289 }290 291 else if (foundRand) {292 this.energy++293 let x = foundRand[0];294 let y = foundRand[1];295 matrix[y][x] = 3296 matrix[this.y][this.x] = 0297 this.x = x298 this.y = y299 for (var i in grassArr) {300 if (x == grassArr[i].x && y == grassArr[i].y) {301 grassArr.splice(i, 1);302 break;303 }304 }305 if (this.energy >= 50) {306 this.mul();307 }308 }309 else {310 this.move()311 }312 }313 die() {314 matrix[this.y][this.x] = 0315 for (var i in predatorArr) {316 if (this.x == predatorArr[i].x && this.y == predatorArr[i].y) {317 predatorArr.splice(i, 1);318 break;319 }320 }321 }322}323class Mulboost {324 constructor(x, y) {325 this.x = x326 this.y = y327 this.directions = [];328 }329 getNewCoordinates() {330 this.directions = [331 [this.x - 1, this.y - 1],332 [this.x, this.y - 1],333 [this.x + 1, this.y - 1],334 [this.x - 1, this.y],335 [this.x + 1, this.y],336 [this.x - 1, this.y + 1],337 [this.x, this.y + 1],338 [this.x + 1, this.y + 1]339 ];340 }341 search(char) {342 this.getNewCoordinates();343 let found = [];344 for (let i in this.directions) {345 let x = this.directions[i][0];346 let y = this.directions[i][1];347 if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {348 if (matrix[y][x] == char) {349 found.push(this.directions[i])350 }351 }352 }353 return found;354 }355 move() {356 let found = this.search(0);357 var foundRand = random(found);358 if (foundRand) {359 let x = foundRand[0];360 let y = foundRand[1];361 matrix[y][x] = matrix[this.y][this.x]362 matrix[this.y][this.x] = 0363 this.x = x364 this.y = y365 }366 }367}368class Virus {369 constructor(x, y) {370 this.x = x;371 this.y = y;372 this.directions = [];373 }374 375 getNewCoordinates() {376 this.directions = [377 [this.x - 1, this.y - 1],378 [this.x, this.y - 1],379 [this.x + 1, this.y - 1],380 [this.x - 1, this.y],381 [this.x + 1, this.y],382 [this.x - 1, this.y + 1],383 [this.x, this.y + 1],384 [this.x + 1, this.y + 1]385 ];386 }387 388 search(char) {389 this.getNewCoordinates();390 let found = [];391 for (let i in this.directions) {392 let x = this.directions[i][0];393 let y = this.directions[i][1];394 if (x >= 0 && x < matrix[0].length && y >= 0 && y < matrix.length) {395 if (matrix[y][x] == char) {396 found.push(this.directions[i])397 }398 }399 }400 return found;401 }402 move() {403 let found = this.search(1);404 var foundRand = random(found);405 if (foundRand) {406 let x = foundRand[0];407 let y = foundRand[1];408 matrix[y][x] = matrix[this.y][this.x]409 matrix[this.y][this.x] = 1410 this.x = x411 this.y = y412 }413 }...

Full Screen

Full Screen

participateController.js

Source:participateController.js Github

copy

Full Screen

1'use strict';2// import {Training} from "../../../src/app/trainings/training";3/**4 * Participate Controller5 * @module participateController6 * @require jwtHelper7 * @require models8 * @require asyncLib9 */10//TODO Use the isSubscribe attribute in DB to know who is participating and who has canceled11const12 jwtHelper = require('../../helpers/jwtHelper'),13 models = require('../../database/models'),14 asyncLib = require('async'),15 unsubscribe = 0,16 subscribe = 1;17let subscribeTraining,18 unsubscribeTraining,19 isParticipateTraining,20 ParticipateUserTraining;21/**22 * @function subscribeTraining23 * @desc Make a user participate to a training if he is authenticated24 * @param req25 * @param res26 * @returns {Object} Training27 */28subscribeTraining = (req, res) =>{29 // Getting auth header30 let headerAuth = req.headers['authorization'];31 let userId = jwtHelper.getUserId(headerAuth);32 let trainingId = parseInt(req.params.trainingId);33 console.log("training id est " + trainingId);34 console.log("user id est " + userId);35 if(trainingId <=0){36 return res.status(400).json({'error': 'invalid parameters'});37 }38 asyncLib.waterfall([39 function(done) {40 models.Training.findOne({41 where: {id: trainingId}42 })43 .then(function(trainingFound){44 done(null, trainingFound);45 })46 .catch(function(err){47 console.log(err);48 return res.status(500).json({ 'error': 'unable to verify training'})49 });50 },51 function(trainingFound, done){52 if(trainingFound) {53 models.User.findOne({54 where: { id: userId}55 })56 .then(function(userFound){57 done(null, trainingFound, userFound);58 })59 .catch(function(err){60 console.log(err);61 return res.status(500).json({ 'error': 'unable to verify user'})62 });63 }else{64 res.status(404).json({ 'error': 'the training doesn\'t exist'});65 }66 },67 function(trainingFound, userFound, done){68 if(userFound){69 models.Participate.findOne({70 where: {71 userId: userId,72 trainingId: trainingId73 }74 })75 .then(function(userAlreadyParticipate){76 done(null, trainingFound, userFound, userAlreadyParticipate);77 })78 .catch(function(err){79 console.log(err);80 return res.status(500).json({ 'error': 'unable to verify if the user already participate to the training'});81 })82 }else{83 res.status(404).json({ 'error': 'the user doesn\'t exist'})84 }85 },86 function(trainingFound, userFound, userAlreadyParticipate, done){87 if(!userAlreadyParticipate && trainingFound.availableSeat > 0){88 trainingFound.addUser(userFound)89 .then(function (alreadyParticipate){90 done(null, trainingFound, userFound);91 })92 .catch(function (err){93 console.log(err);94 return res.status(500).json({ 'error' : 'unable to set user participation'});95 })96 }else {97 res.status(409).json({ 'error': 'user already participate or there is no more available seat' });98 }99 },100 function(trainingFound, userFound, done){101 if(trainingFound.availableSeat > 0){102 trainingFound.update({103 availableSeat: trainingFound.availableSeat - 1,104 }).then(function(){105 done(trainingFound);106 }).catch(function(err){107 res.status(500).json({ 'error': 'can\'t update the training\'s available seat'});108 });109 }else{110 res.status(409).json({ 'error': 'There is no more available seat' });111 }112 },113 ], function(trainingFound) {114 if(trainingFound){115 return res.status(201).json(trainingFound);116 }else{117 return res.status(500).json({'error': 'can\'t update available seat'})118 }119 }120 )121};122/**123 * @function unsubscribeTraining124 * @desc Make a user unsubscribe to a training if he is authenticated and if he subscribe to it in a first place125 * @param req126 * @param res127 * @returns {Object} Training128 */129unsubscribeTraining = (req, res) => {130 // Getting auth header131 let headerAuth = req.headers['authorization'];132 let userId = jwtHelper.getUserId(headerAuth);133 let trainingId = parseInt(req.params.trainingId);134 if(trainingId <=0){135 return res.status(400).json({'error': 'invalid parameters'});136 }137 asyncLib.waterfall([138 function(done) {139 models.Training.findOne({140 where: {id: trainingId}141 })142 .then(function(trainingFound){143 done(null, trainingFound);144 })145 .catch(function(err){146 console.log(err);147 return res.status(500).json({ 'error': 'unable to verify training'})148 });149 },150 function(trainingFound, done){151 if(trainingFound) {152 models.User.findOne({153 where: { id: userId}154 })155 .then(function(userFound){156 done(null, trainingFound, userFound);157 })158 .catch(function(err){159 console.log(err);160 return res.status(500).json({ 'error': 'unable to verify user'})161 });162 }else{163 res.status(404).json({ 'error': 'the training doesn\'t exist'});164 }165 },166 function(trainingFound, userFound, done){167 if(userFound){168 models.Participate.findOne({169 where: {170 userId: userId,171 trainingId: trainingId172 }173 })174 .then(function(userAlreadyParticipate){175 done(null, trainingFound, userFound, userAlreadyParticipate);176 })177 .catch(function(err){178 console.log(err);179 return res.status(500).json({ 'error': 'unable to verify if the user already participate to the training'});180 })181 }else{182 res.status(404).json({ 'error': 'the user doesn\'t exist'})183 }184 },185 function(trainingFound, userFound, userAlreadyParticipate, done){186 if(userAlreadyParticipate){187 userAlreadyParticipate.destroy()188 .then(function (doNotParticipate){189 done(null, trainingFound, userFound);190 })191 .catch(function (err){192 console.log(err);193 return res.status(500).json({ 'error' : 'cannot remove user participation'});194 })195 }else{196 res.status(409).json({'error': 'the user has already unsubscribe to the training'})197 }198 },199 function(trainingFound, userFound, done){200 trainingFound.update({201 availableSeat: trainingFound.availableSeat + 1,202 }).then(function(){203 done(trainingFound);204 }).catch(function(err){205 console.log(err);206 res.status(500).json({ 'error': 'can\'t update the training\'s available seat'});207 });208 },209 ], function(trainingFound) {210 if(trainingFound){211 return res.status(201).json(trainingFound);212 }else{213 return res.status(500).json({'error': 'can\'t update available seat'})214 }215 }216 )217};218/**219 * @function unsubscribeTraining220 * @desc Let know if a user is already participating in training221 * @param req222 * @param res223 * @returns {Object} Training224 */225isParticipateTraining = (req, res) => {226 // Getting auth header227 let headerAuth = req.headers['authorization'],228 userId = jwtHelper.getUserId(headerAuth),229 trainingId = parseInt(req.params.trainingId);230 let participate = false;231 console.log("training id est " + trainingId);232 console.log("user id est " + userId);233 if(trainingId <=0){234 return res.status(400).json({'error': 'invalid parameters'});235 }236 asyncLib.waterfall([237 function(done) {238 models.Training.findOne({239 where: {id: trainingId}240 })241 .then(function(trainingFound){242 done(null, trainingFound);243 })244 .catch(function(err){245 console.log(err);246 return res.status(500).json({ 'error': 'unable to verify training'})247 });248 },249 function(trainingFound, done){250 if(trainingFound) {251 models.User.findOne({252 where: { id: userId}253 })254 .then(function(userFound){255 done(null, trainingFound, userFound);256 })257 .catch(function(err){258 console.log(err);259 return res.status(500).json({ 'error': 'unable to verify user'})260 });261 }else{262 res.status(404).json({ 'error': 'the training doesn\'t exist'});263 }264 },265 function(trainingFound, userFound, done){266 if(userFound){267 models.Participate.findOne({268 where: {269 userId: userId,270 trainingId: trainingId271 }272 })273 .then(function(userAlreadyParticipate){274 if(userAlreadyParticipate){275 participate = true;276 }277 done(null, trainingFound, userFound, userAlreadyParticipate);278 })279 .catch(function(err){280 console.log(err);281 return res.status(500).json({ 'error': 'unable to verify if the user already participate to the training'});282 })283 }else{284 res.status(404).json({ 'error': 'the user doesn\'t exist'})285 }286 },287 ], function(trainingFound) {288 if(participate){289 return res.status(201).json(participate);290 }else{291 return res.status(201).json(participate)292 }293 }294 )295};296/**297 * @function unsubscribeTraining298 * @desc Send back the training for which the user have been subscribed299 * @param req300 * @param res301 * @returns {Object} Training302 */303ParticipateUserTraining = (req, res) => {304 // Getting auth header305 let headerAuth = req.headers['authorization'],306 userId = jwtHelper.getUserId(headerAuth);307 models.Participate.findAll({308 include: [{309 model: models.Training, as: 'training',310 }],311 where: {userId: userId}312 }).then(function(training) {313 if (training) {314 res.status(200).json(training);315 } else {316 res.status(404).json({ "error": "no Training found" });317 }318 }).catch(function(err) {319 console.log(err);320 res.status(500).json({ "error": "invalid fields" });321 });322};323module.exports = {324 subscribeTraining,325 unsubscribeTraining,326 isParticipateTraining,327 ParticipateUserTraining...

Full Screen

Full Screen

tap.js

Source:tap.js Github

copy

Full Screen

1const tap = require('tap');2function approx(a, b, maxDiff) {3 maxDiff = maxDiff || 0.000001;4 return Math.abs(a - b) <= maxDiff;5}6tap.Test.prototype.addAssert('approx', 3, function (found, wanted, maxDifferent, message, extra ) {7 let diff = Math.abs(found - wanted);8 maxDifferent = maxDifferent || 0.0001;9 message = message || `should be approximate (${maxDifferent})`;10 if ( diff <= maxDifferent ) {11 return this.pass(message, extra);12 }13 extra.found = found;14 extra.wanted = wanted;15 extra.compare = '~=';16 return this.fail(message, extra);17});18tap.Test.prototype.addAssert('deepApprox', 3, function (found, wanted, maxDifferent, message, extra ) {19 maxDifferent = maxDifferent || 0.0001;20 message = message || `should be approximate (${maxDifferent})`;21 for ( let name in found ) {22 let diff = Math.abs(found[name] - wanted[name]);23 if (diff > maxDifferent) {24 extra.found = found;25 extra.wanted = wanted;26 extra.compare = '~=';27 return this.fail(message, extra);28 }29 }30 return this.pass(message, extra);31});32tap.Test.prototype.addAssert('approxArray', 3, function (found, wanted, maxDifferent, message, extra ) {33 if ( found.length !== wanted.length ) {34 return this.fail(message, extra);35 }36 maxDifferent = maxDifferent || 0.0001;37 message = message || `should be approximate (${maxDifferent})`;38 for ( let i = 0; i < found.length; ++i ) {39 let diff = Math.abs(found[i] - wanted[i]);40 if (diff <= maxDifferent) {41 return this.pass(message, extra);42 }43 }44 extra.found = found;45 extra.wanted = wanted;46 extra.compare = '~=';47 return this.fail(message, extra);48});49tap.Test.prototype.addAssert('notApprox', 3, function (found, wanted, maxDifferent, message, extra ) {50 let diff = Math.abs(found - wanted);51 maxDifferent = maxDifferent || 0.0001;52 message = message || `should be not approximate (${maxDifferent})`;53 if ( diff > maxDifferent ) {54 return this.pass(message, extra);55 }56 extra.found = found;57 extra.wanted = wanted;58 extra.compare = '!~=';59 return this.fail(message, extra);60});61tap.Test.prototype.addAssert('equal_v2', 2, function (found, wanted, message, extra ) {62 let result = approx(found.x, wanted[0]) && approx(found.y, wanted[1]);63 if ( result ) {64 return this.pass(message, extra);65 }66 extra.found = found;67 extra.wanted = wanted;68 extra.compare = '~=';69 return this.fail(message, extra);70});71tap.Test.prototype.addAssert('equal_v3', 2, function (found, wanted, message, extra ) {72 let result = approx(found.x, wanted[0]) && approx(found.y, wanted[1]) && approx(found.z, wanted[2]);73 if ( result ) {74 return this.pass(message, extra);75 }76 extra.found = found;77 extra.wanted = wanted;78 extra.compare = '~=';79 return this.fail(message, extra);80});81tap.Test.prototype.addAssert('equal_v4', 2, function (found, wanted, message, extra ) {82 let result = approx(found.x, wanted[0]) && approx(found.y, wanted[1]) && approx(found.z, wanted[2]) && approx(found.w, wanted[3]);83 if ( result ) {84 return this.pass(message, extra);85 }86 extra.found = found;87 extra.wanted = wanted;88 extra.compare = '~=';89 return this.fail(message, extra);90});91tap.Test.prototype.addAssert('equal_c3', 2, function (found, wanted, message, extra ) {92 let result = approx(found.r, wanted[0]) && approx(found.g, wanted[1]) && approx(found.b, wanted[2]);93 if ( result ) {94 return this.pass(message, extra);95 }96 extra.found = found;97 extra.wanted = wanted;98 extra.compare = '~=';99 return this.fail(message, extra);100});101tap.Test.prototype.addAssert('equal_c4', 2, function (found, wanted, message, extra ) {102 let result = approx(found.r, wanted[0]) && approx(found.g, wanted[1]) && approx(found.b, wanted[2]) && approx(found.a, wanted[3]);103 if ( result ) {104 return this.pass(message, extra);105 }106 extra.found = found;107 extra.wanted = wanted;108 extra.compare = '~=';109 return this.fail(message, extra);110});111tap.Test.prototype.addAssert('equal_m2', 2, function (found, wanted, message, extra ) {112 let result =113 approx(found.m00, wanted[0]) &&114 approx(found.m01, wanted[1]) &&115 approx(found.m02, wanted[2]) &&116 approx(found.m03, wanted[3])117 ;118 if ( result ) {119 return this.pass(message, extra);120 }121 extra.found = found;122 extra.wanted = wanted;123 extra.compare = '~=';124 return this.fail(message, extra);125});126tap.Test.prototype.addAssert('equal_m23', 2, function (found, wanted, message, extra ) {127 let result =128 approx(found.m00, wanted[0]) &&129 approx(found.m01, wanted[1]) &&130 approx(found.m02, wanted[2]) &&131 approx(found.m03, wanted[3]) &&132 approx(found.m04, wanted[4]) &&133 approx(found.m05, wanted[5])134 ;135 if ( result ) {136 return this.pass(message, extra);137 }138 extra.found = found;139 extra.wanted = wanted;140 extra.compare = '~=';141 return this.fail(message, extra);142});143tap.Test.prototype.addAssert('equal_m3', 2, function (found, wanted, message, extra ) {144 let result =145 approx(found.m00, wanted[0]) &&146 approx(found.m01, wanted[1]) &&147 approx(found.m02, wanted[2]) &&148 approx(found.m03, wanted[3]) &&149 approx(found.m04, wanted[4]) &&150 approx(found.m05, wanted[5]) &&151 approx(found.m06, wanted[6]) &&152 approx(found.m07, wanted[7]) &&153 approx(found.m08, wanted[8])154 ;155 if ( result ) {156 return this.pass(message, extra);157 }158 extra.found = found;159 extra.wanted = wanted;160 extra.compare = '~=';161 return this.fail(message, extra);162});163tap.Test.prototype.addAssert('equal_m4', 2, function (found, wanted, message, extra ) {164 let result =165 approx(found.m00, wanted[0]) &&166 approx(found.m01, wanted[1]) &&167 approx(found.m02, wanted[2]) &&168 approx(found.m03, wanted[3]) &&169 approx(found.m04, wanted[4]) &&170 approx(found.m05, wanted[5]) &&171 approx(found.m06, wanted[6]) &&172 approx(found.m07, wanted[7]) &&173 approx(found.m08, wanted[8]) &&174 approx(found.m09, wanted[9]) &&175 approx(found.m10, wanted[10]) &&176 approx(found.m11, wanted[11]) &&177 approx(found.m12, wanted[12]) &&178 approx(found.m13, wanted[13]) &&179 approx(found.m14, wanted[14]) &&180 approx(found.m15, wanted[15])181 ;182 if ( result ) {183 return this.pass(message, extra);184 }185 extra.found = found;186 extra.wanted = wanted;187 extra.compare = '~=';188 return this.fail(message, extra);189});...

Full Screen

Full Screen

get-active-candidate-votes.js

Source:get-active-candidate-votes.js Github

copy

Full Screen

1import middyfy from 'middleware';2import createHttpError from 'http-errors';3import {4 getCandidate,5 getSessionAndCandidateVotes,6 getVote,7 getAllSessions,8 getMultiCandidates,9 getVotesBySession,10 getSessionVotes11} from 'services/voting';12const getRegular = async ({ event, foundSessions, activeSession }) => {13 const foundCandidate = await getCandidate(activeSession.currentCandidateId);14 if (!foundCandidate.success) {15 throw new createHttpError.InternalServerError('Could not get candidate');16 }17 console.log('Found candidate', foundCandidate);18 if (!foundCandidate.data.candidate) {19 return {20 statusCode: 200,21 body: {22 candidate: null,23 candidates: [],24 sessions: [],25 votes: []26 }27 };28 }29 let foundVotes;30 if (event.user.privileged) {31 foundVotes = await getSessionAndCandidateVotes(activeSession._id, foundCandidate.data.candidate._id);32 } else {33 foundVotes = await getVote(event.user.email, activeSession._id, foundCandidate.data.candidate._id);34 if (foundVotes.success) {35 foundVotes.data.votes = foundVotes.data.vote ? [foundVotes.data.vote] : [];36 }37 }38 if (!foundVotes.success) {39 throw new createHttpError.InternalServerError('Could not get votes');40 }41 console.log('Found votes', foundVotes.data.votes.length);42 return {43 statusCode: 200,44 body: {45 sessions: foundSessions.data.sessions,46 candidate: foundCandidate.data.candidate,47 votes: foundVotes.data.votes48 }49 };50};51const getMulti = async ({ event, foundSessions, activeSession }) => {52 const foundCandidates = await getMultiCandidates(activeSession.candidateOrder);53 if (!foundCandidates.success) {54 throw new createHttpError.InternalServerError('Could not get candidates');55 }56 console.log('Found candidates', foundCandidates.data.candidates.length);57 if (foundCandidates.data.candidates.length === 0) {58 return {59 statusCode: 200,60 body: {61 candidate: null,62 candidates: [],63 sessions: [],64 votes: []65 }66 };67 }68 let foundVotes;69 if (event.user.privileged) {70 foundVotes = await getSessionVotes(activeSession._id);71 } else {72 foundVotes = await getVotesBySession(event.user.email, activeSession._id);73 }74 if (!foundVotes.success) {75 throw new createHttpError.InternalServerError('Could not get votes');76 }77 // console.log('Found votes', foundVotes);78 return {79 statusCode: 200,80 body: {81 sessions: foundSessions.data.sessions,82 candidates: foundCandidates.data.candidates,83 votes: foundVotes.data.votes84 }85 };86};87const _handler = async (event, context) => {88 if (!event.authorized) {89 throw new createHttpError.Unauthorized('Not authorized');90 }91 const foundSessions = await getAllSessions();92 if (!foundSessions.success) {93 throw new createHttpError.InternalServerError('Could not get session');94 }95 const activeSession = foundSessions.data.sessions.find((session) => session.active === true);96 console.log('Found session', activeSession);97 if (!activeSession) {98 return {99 statusCode: 200,100 body: {101 candidate: null,102 candidates: [],103 sessions: [],104 votes: []105 }106 };107 }108 if (activeSession.type === 'MULTI') {109 return getMulti({ event, foundSessions, activeSession });110 }111 return getRegular({ event, foundSessions, activeSession });112};113export const handler = middyfy(_handler, {114 authorized: true,115 useMongo: true...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { storiesOf, action, linkTo } = require('storybook-root').found;2storiesOf('Button', module)3 .add('with text', () => (4 <button onClick={action('clicked')}>Hello Button</button>5 .add('with some emoji', () => (6 <button onClick={action('clicked')}>πŸ˜€ 😎 πŸ‘ πŸ’―</button>7 ));8storiesOf('Link', module)9 .add('with text', () => (10 <a href="#" onClick={linkTo('Button', 'with text')}>Go to Button</a>11 .add('with some emoji', () => (12 <a href="#" onClick={linkTo('Button', 'with some emoji')}>Go to Button</a>13 ));14import { configure } from '@kadira/

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const storybookRootPath = storybookRoot.found();3console.log(`storybookRootPath = ${storybookRootPath}`);4const storybookRoot = require('storybook-root');5const storybookRootPath = storybookRoot.found();6console.log(`storybookRootPath = ${storybookRootPath}`);7const storybookRoot = require('storybook-root');8const storybookRootPath = storybookRoot.found();9console.log(`storybookRootPath = ${storybookRootPath}`);10const storybookRoot = require('storybook-root');11const storybookRootPath = storybookRoot.found();12console.log(`storybookRootPath = ${storybookRootPath}`);13const storybookRoot = require('storybook-root');14const storybookRootPath = storybookRoot.found();15console.log(`storybookRootPath = ${storybookRootPath}`);16const storybookRoot = require('storybook-root');17const storybookRootPath = storybookRoot.found();18console.log(`storybookRootPath = ${storybookRootPath}`);19const storybookRoot = require('storybook-root');20const storybookRootPath = storybookRoot.found();21console.log(`storybookRootPath = ${storybookRootPath}`);22const storybookRoot = require('storybook-root');23const storybookRootPath = storybookRoot.found();24console.log(`storybookRootPath = ${storybookRootPath}`);25const storybookRoot = require('storybook-root');26const storybookRootPath = storybookRoot.found();27console.log(`storybookRootPath = ${storybookRootPath}`);28const storybookRoot = require('storybook-root');29const storybookRootPath = storybookRoot.found();30console.log(`storybookRootPath = ${storybookRootPath}`);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from 'storybook-root';2storiesOf('test', module)3 .add('test', () => <div>test</div>);4import { configure } from '@storybook/react';5import { setStorybookRoot } from 'storybook-root';6setStorybookRoot(__dirname);7configure(() => {8}, module);9const path = require('path');10const storybookRoot = require('storybook-root');11module.exports = {12 resolve: {13 alias: {14 'storybook-root': path.join(storybookRoot, 'src/index.js'),15 },16 },17};18"scripts": {19}

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = await page.$('storybook-root');2const found = await storybookRoot.$('some-selector');3const storybookRoot = await page.$('storybook-root');4const found = await storybookRoot.$('some-selector');5const storybookRoot = await page.$('storybook-root');6const found = await storybookRoot.$('some-selector');7const storybookRoot = await page.$('storybook-root');8const found = await storybookRoot.$('some-selector');9const storybookRoot = await page.$('storybook-root');10const found = await storybookRoot.$('some-selector');11const storybookRoot = await page.$('storybook-root');12const found = await storybookRoot.$('some-selector');13const storybookRoot = await page.$('storybook-root');14const found = await storybookRoot.$('some-selector');15const storybookRoot = await page.$('storybook-root');16const found = await storybookRoot.$('some-selector');17const storybookRoot = await page.$('storybook-root');18const found = await storybookRoot.$('some-selector');19const storybookRoot = await page.$('storybook-root');20const found = await storybookRoot.$('some-selector');21const storybookRoot = await page.$('storybook-root');22const found = await storybookRoot.$('some-selector');23const storybookRoot = await page.$('storybook-root');24const found = await storybookRoot.$('some-selector');

Full Screen

Using AI Code Generation

copy

Full Screen

1import {configure, addDecorator, addParameters} from 'storybook-root'2import {withKnobs} from '@storybook/addon-knobs'3addParameters({options: {name: 'My Storybook'}})4addDecorator(withKnobs)5configure(require.context('./stories', true, /\.js$/), module)6import React from 'react'7import {storiesOf} from 'storybook-root'8storiesOf('Hello World', module)9 .add('with text', () => <div>Hello World</div>)10 .add('with emoji', () => <div>πŸ˜€ 😎 πŸ‘ πŸ’―</div>)11import 'storybook-root/register'12import 'storybook-root/config'13module.exports = require('storybook-root/webpack.config')14import {addons} from 'storybook-root'15import {create} from '@storybook/theming'16addons.setConfig({17 theme: create({18 }),19})20import {addDecorator} from 'storybook-root'21import {withKnobs} from '@storybook/addon-knobs'22addDecorator(withKnobs)

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const storybookRoot = require('storybook-root');3const storybookRootPath = storybookRoot.getStorybookRootPath();4console.log(storybookRootPath);5const storybookRootPath2 = storybookRoot.getStorybookRootPath({6 cwd: path.join(__dirname, 'src'),7});8console.log(storybookRootPath2);9const storybookRootPath3 = storybookRoot.getStorybookRootPath({10 cwd: path.join(__dirname, 'src', 'components'),11});12console.log(storybookRootPath3);13const storybookRootPath4 = storybookRoot.getStorybookRootPath({14 cwd: path.join(__dirname, 'src', 'components', 'Button'),15});16console.log(storybookRootPath4);17const storybookRootPath5 = storybookRoot.getStorybookRootPath({18 cwd: path.join(__dirname, 'src', 'components', 'Button', 'Button.stories.js'),19});20console.log(storybookRootPath5);21const storybookRootPath6 = storybookRoot.getStorybookRootPath({22 cwd: path.join(__dirname, 'src', 'components', 'Button', 'Button.stories.jsx'),23});24console.log(storybookRootPath6);25const storybookRootPath7 = storybookRoot.getStorybookRootPath({26 cwd: path.join(__dirname, 'src', 'components', 'Button', 'Button.stories.ts'),27});28console.log(storybookRootPath7);29const storybookRootPath8 = storybookRoot.getStorybookRootPath({30 cwd: path.join(__dirname, 'src', 'components', 'Button', 'Button.stories.tsx'),31});32console.log(storybookRootPath8);33const storybookRootPath9 = storybookRoot.getStorybookRootPath({34 cwd: path.join(__dirname, 'src', 'components', 'Button', 'Button.st

Full Screen

Using AI Code Generation

copy

Full Screen

1const { found } = require('storybook-root');2const { Storybook } = require('./lib/index.js');3const { storiesOf } = require('@storybook/react');4const { action } = require('@storybook/addon-actions');5const storybook = new Storybook();6storybook.addStory(storiesOf('My test', module)7 .add('test', () => (8 <button onClick={action('clicked')}>Click me</button>9);10storybook.addStory(storiesOf('My test', module)11 .add('test2', () => (12 <button onClick={action('clicked')}>Click me</button>13);14found(storybook);15const { Storybook } = require('./lib/index.js');16const { storiesOf } = require('@storybook/react');17const { action } = require('@storybook/addon-actions');18const { expect } = require('chai');19describe('My test', () => {20 it('should do something', () => {21 const storybook = new Storybook();22 storybook.addStory(storiesOf('My test', module)23 .add('test', () => (24 <button onClick={action('clicked')}>Click me</button>25 );26 storybook.addStory(storiesOf('My test', module)27 .add('test2', () => (28 <button onClick={action('clicked')}>Click me</button>29 );30 const story = storybook.find('test');31 expect(story).to.be.ok;32 });33});34#### `new Storybook()`35#### `storybook.addStory(story)`36#### `storybook.find(name)`37#### `storybook.findWhere(predicate)`

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function (storybookRoot) {2 storybookRoot.found('a', function (element) {3 element.click(function () {4 });5 });6};7import storybookRoot from 'storybook-root';8import test from './test';9storybookRoot.register(test);10storiesOf('My Component', module)11 .add('with text', () => (12 ));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful