-Updated to .NET Standard 1.4.
-Moved HTML related classes, namespaces and formatters to ColorCode.HTML. This is a .NET Standard 2.0 Project, due to System.Drawing.Color. -Replaced IFormatter, ICodeColorizer, CodeColorizer, with CodeColorizerBase, this is because different outputs will require different parameters, and produce different outputs. -Removed Facts and AcceptanceTests, as they were causing compilation issues, and don't use the new Classes. -Removed old Build System. -Added ColorCode.UWP Stub. -Added inherited MS-PL license.
This commit is contained in:
Родитель
ab8a7c19df
Коммит
d0cb635e10
|
@ -0,0 +1,63 @@
|
|||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
|
@ -1,32 +1,294 @@
|
|||
BuildResults.xml
|
||||
ColorCode.AcceptanceTests.xunit.results.xml
|
||||
ColorCode.AcceptanceTests/Data/asax/class.actual.html
|
||||
ColorCode.AcceptanceTests/Data/ashx/simple.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/abstract-keyword.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/as-keyword.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/assembly-attribute.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/base-keyword.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/comments.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/correct-classname.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/linq-keyword.actual.html
|
||||
ColorCode.AcceptanceTests/Data/csharp/strings.actual.html
|
||||
ColorCode.AcceptanceTests/Data/css/sample.actual.html
|
||||
ColorCode.AcceptanceTests/Data/php/sample.actual.html
|
||||
ColorCode.AcceptanceTests/Data/ps/keywords.actual.html
|
||||
ColorCode.AcceptanceTests/Data/ps/multilinecomments.actual.html
|
||||
ColorCode.AcceptanceTests/Data/ps/operators.actual.html
|
||||
ColorCode.AcceptanceTests/Data/ps/sample.actual.html
|
||||
ColorCode.AcceptanceTests/Data/sql/aggregate-functions.actual.html
|
||||
ColorCode.AcceptanceTests/Data/sql/keyword-color.actual.html
|
||||
ColorCode.AcceptanceTests/Data/sql/math-functions.actual.html
|
||||
ColorCode.AcceptanceTests/Data/sql/system-function-color.actual.html
|
||||
ColorCode.AcceptanceTests/Data/vb/linq-keyword.actual.html
|
||||
ColorCode.AcceptanceTests/Data/vb/strings.actual.html
|
||||
ColorCode.AcceptanceTests/Data/xml/xml-stylesheet.actual.html
|
||||
ColorCode.AcceptanceTests/Data/fsharp/fsharp-tutorial.actual.html
|
||||
ColorCode.AcceptanceTests/obj/
|
||||
ColorCode.Facts.xunit.results.xml
|
||||
ColorCode.Facts/obj/
|
||||
ColorCode.v11.suo
|
||||
ColorCode/obj/
|
||||
_ReSharper.ColorCode/
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# XUNIT
|
||||
*.xunit.results.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
/_build/tools
|
||||
|
||||
BuildResults.xml
|
|
@ -1,7 +0,0 @@
|
|||
relre:.+/(bin|obj)/.+
|
||||
relre:_ReSharper.+
|
||||
glob:ColorCode.suo
|
||||
glob:BuildResults.xml
|
||||
relre:ColorCode\.AcceptanceTests.+\.actual\..+
|
||||
relre:.+xunit\.results\.xml
|
||||
relre:.+\.csproj\.user
|
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -1,117 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output method="html"/>
|
||||
<xsl:template match="/">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="assembly">
|
||||
<xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">]]></xsl:text>
|
||||
<html>
|
||||
<head>
|
||||
<title>xUnit.net Test Results - <xsl:value-of select="@name"/>
|
||||
</title>
|
||||
<style type="text/css">
|
||||
body { font-family: Calibri, Verdana, Arial, sans-serif; background-color: White; color: Black; }
|
||||
h2,h3,h5 { margin: 0; padding: 0; }
|
||||
h2 { border-top: solid 1px #f0f5fa; padding-top: 0.5em; }
|
||||
h3 { font-weight: normal; }
|
||||
h5 { font-weight: normal; font-style: italic; margin-bottom: 0.75em; }
|
||||
pre { font-family: Consolas; font-size: 85%; margin: 0 0 0 1em; padding: 0; }
|
||||
.row, .altrow { padding: 0.1em 0.3em; }
|
||||
.row { background-color: #f0f5fa; }
|
||||
.altrow { background-color: #e1ebf4; }
|
||||
.success, .failure, .skipped { font-family: Arial Unicode MS; font-weight: normal; float: left; width: 1em; display: block; }
|
||||
.success { color: #0c0; }
|
||||
.failure { color: #c00; }
|
||||
.skipped { color: #cc0; }
|
||||
.timing { float: right; }
|
||||
.indent { margin: 0.25em 0 0.5em 2em; }
|
||||
.clickable { cursor: pointer; }
|
||||
.testcount { font-size: 85%; }
|
||||
</style>
|
||||
<script language="javascript">
|
||||
function ToggleClass(id) {
|
||||
var elem = document.getElementById(id);
|
||||
if (elem.style.display == "none")
|
||||
elem.style.display = "block";
|
||||
else
|
||||
elem.style.display = "none";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h3><b>Results for <xsl:value-of select="@name"/></b></h3>
|
||||
<div>
|
||||
Tests run: <a href="#all"><b><xsl:value-of select="@total"/></b></a>  
|
||||
Failures: <a href="#failures"><b><xsl:value-of select="@failed"/></b></a>,
|
||||
Skipped: <a href="#skipped"><b><xsl:value-of select="@skipped"/></b></a>,
|
||||
Run time: <b><xsl:value-of select="@time"/>s</b>
|
||||
</div>
|
||||
<xsl:if test="//test[@result='Fail']">
|
||||
<br />
|
||||
<h2><a name="failures"></a>Failed tests</h2>
|
||||
<xsl:apply-templates select="//test[@result='Fail']"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
</xsl:if>
|
||||
<xsl:if test="//class/failure">
|
||||
<br />
|
||||
<h2><a name="failures"></a>Failed fixtures</h2>
|
||||
<xsl:apply-templates select="//class/failure"><xsl:sort select="../@name"/></xsl:apply-templates>
|
||||
</xsl:if>
|
||||
<xsl:if test="@skipped > 0">
|
||||
<br />
|
||||
<h2><a name="skipped"></a>Skipped tests</h2>
|
||||
<xsl:apply-templates select="//test[@result='Skip']"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
</xsl:if>
|
||||
<br />
|
||||
<h2><a name="all"></a>All tests</h2>
|
||||
<h5>Click test class name to expand/collapse test details</h5>
|
||||
<xsl:apply-templates select="//class"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
<br /><h5>Results generated <xsl:value-of select="@run-date"/> at <xsl:value-of select="@run-time"/></h5>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="test">
|
||||
<div>
|
||||
<xsl:attribute name="class"><xsl:if test="(position() mod 2 = 0)">alt</xsl:if>row</xsl:attribute>
|
||||
<xsl:if test="@result!='Skip'"><span class="timing"><xsl:value-of select="@time"/>s</span></xsl:if>
|
||||
<xsl:if test="@result='Skip'"><span class="timing">Skipped</span><span class="skipped">❢</span></xsl:if>
|
||||
<xsl:if test="@result='Fail'"><span class="failure">✘</span></xsl:if>
|
||||
<xsl:if test="@result='Pass'"><span class="success">✔</span></xsl:if>
|
||||
 <xsl:value-of select="@name"/>
|
||||
<xsl:if test="child::node()/message"> : <xsl:value-of select="child::node()/message"/></xsl:if>
|
||||
<br clear="all" />
|
||||
<xsl:if test="failure/stack-trace">
|
||||
<pre><xsl:value-of select="failure/stack-trace"/></pre>
|
||||
</xsl:if>
|
||||
</div>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="failure">
|
||||
<span class="failure">✘</span> <xsl:value-of select="../@name"/> : <xsl:value-of select="message"/><br clear="all"/>
|
||||
Stack Trace:<br />
|
||||
<pre><xsl:value-of select="stack-trace"/></pre>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="class">
|
||||
<h3>
|
||||
<span class="timing"><xsl:value-of select="@time"/>s</span>
|
||||
<span class="clickable">
|
||||
<xsl:attribute name="onclick">ToggleClass('class<xsl:value-of select="position()"/>')</xsl:attribute>
|
||||
<xsl:attribute name="ondblclick">ToggleClass('class<xsl:value-of select="position()"/>')</xsl:attribute>
|
||||
<xsl:if test="@failed > 0"><span class="failure">✘</span></xsl:if>
|
||||
<xsl:if test="@failed = 0"><span class="success">✔</span></xsl:if>
|
||||
 <xsl:value-of select="@name"/>
|
||||
 <span class="testcount">(<xsl:value-of select="@total"/> test<xsl:if test="@total > 1">s</xsl:if>)</span>
|
||||
</span>
|
||||
<br clear="all" />
|
||||
</h3>
|
||||
<div class="indent">
|
||||
<xsl:if test="@failed = 0"><xsl:attribute name="style">display: none;</xsl:attribute></xsl:if>
|
||||
<xsl:attribute name="id">class<xsl:value-of select="position()"/></xsl:attribute>
|
||||
<xsl:apply-templates select="test"><xsl:sort select="@name"/></xsl:apply-templates>
|
||||
</div>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
|
@ -1,121 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output cdata-section-elements="message stack-trace"/>
|
||||
|
||||
<xsl:template match="/">
|
||||
<xsl:apply-templates/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="assembly">
|
||||
<test-results>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="date">
|
||||
<xsl:value-of select="@run-date"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="time">
|
||||
<xsl:value-of select="@run-time"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="total">
|
||||
<xsl:value-of select="@total"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="failures">
|
||||
<xsl:value-of select="@failed"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="not-run">
|
||||
<xsl:value-of select="@skipped"/>
|
||||
</xsl:attribute>
|
||||
<test-suite>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="success">
|
||||
<xsl:if test="@failed > 0">False</xsl:if>
|
||||
<xsl:if test="@failed = 0">True</xsl:if>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="time">
|
||||
<xsl:value-of select="@time"/>
|
||||
</xsl:attribute>
|
||||
<results>
|
||||
<xsl:apply-templates select="class"/>
|
||||
</results>
|
||||
</test-suite>
|
||||
</test-results>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="class">
|
||||
<test-suite>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="success">
|
||||
<xsl:if test="@failed > 0">False</xsl:if>
|
||||
<xsl:if test="@failed = 0">True</xsl:if>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="time">
|
||||
<xsl:value-of select="@time"/>
|
||||
</xsl:attribute>
|
||||
<xsl:if test="failure">
|
||||
<xsl:copy-of select="failure"/>
|
||||
</xsl:if>
|
||||
<xsl:if test="reason">
|
||||
<reason>
|
||||
<xsl:apply-templates select="reason"/>
|
||||
</reason>
|
||||
</xsl:if>
|
||||
<results>
|
||||
<xsl:apply-templates select="test"/>
|
||||
</results>
|
||||
</test-suite>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="test">
|
||||
<test-case>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="executed">
|
||||
<xsl:if test="@result='Skip'">False</xsl:if>
|
||||
<xsl:if test="@result!='Skip'">True</xsl:if>
|
||||
</xsl:attribute>
|
||||
<xsl:if test="@result!='Skip'">
|
||||
<xsl:attribute name="success">
|
||||
<xsl:if test="@result='Fail'">False</xsl:if>
|
||||
<xsl:if test="@result='Pass'">True</xsl:if>
|
||||
</xsl:attribute>
|
||||
</xsl:if>
|
||||
<xsl:if test="@time">
|
||||
<xsl:attribute name="time">
|
||||
<xsl:value-of select="@time"/>
|
||||
</xsl:attribute>
|
||||
</xsl:if>
|
||||
<xsl:apply-templates select="traits"/>
|
||||
<xsl:apply-templates select="failure"/>
|
||||
</test-case>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="traits">
|
||||
<properties>
|
||||
<xsl:apply-templates select="trait"/>
|
||||
</properties>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="trait">
|
||||
<property>
|
||||
<xsl:attribute name="name">
|
||||
<xsl:value-of select="@name"/>
|
||||
</xsl:attribute>
|
||||
<xsl:attribute name="value">
|
||||
<xsl:value-of select="@value"/>
|
||||
</xsl:attribute>
|
||||
</property>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="failure">
|
||||
<failure>
|
||||
<xsl:copy-of select="node()"/>
|
||||
</failure>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
Двоичный файл не отображается.
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
|
||||
<configSections>
|
||||
<section name="xunit" type="Xunit.ConsoleClient.XunitConsoleConfigurationSection, xunit.console"/>
|
||||
</configSections>
|
||||
|
||||
<xunit>
|
||||
<transforms>
|
||||
<add
|
||||
commandline="html"
|
||||
xslfile="HTML.xslt"
|
||||
description="output results to HTML file"/>
|
||||
<add
|
||||
commandline="nunit"
|
||||
xslfile="NUnitXml.xslt"
|
||||
description="output results to NUnit-style XML file"/>
|
||||
</transforms>
|
||||
</xunit>
|
||||
|
||||
</configuration>
|
Двоичный файл не отображается.
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
|
||||
<configSections>
|
||||
<section name="xunit" type="Xunit.ConsoleClient.XunitConsoleConfigurationSection, xunit.console.x86"/>
|
||||
</configSections>
|
||||
|
||||
<xunit>
|
||||
<transforms>
|
||||
<add
|
||||
commandline="html"
|
||||
xslfile="HTML.xslt"
|
||||
description="output results to HTML file"/>
|
||||
<add
|
||||
commandline="nunit"
|
||||
xslfile="NUnitXml.xslt"
|
||||
description="output results to NUnit-style XML file"/>
|
||||
</transforms>
|
||||
</xunit>
|
||||
|
||||
</configuration>
|
Двоичный файл не отображается.
|
@ -1,5 +0,0 @@
|
|||
<TestRunner>
|
||||
<FriendlyName>xUnit.net {0}.{1} build {3}</FriendlyName>
|
||||
<AssemblyPath>xunit.runner.tdnet.dll</AssemblyPath>
|
||||
<TypeName>Xunit.Runner.TdNet.TdNetRunner</TypeName>
|
||||
</TestRunner>
|
Двоичный файл не отображается.
|
@ -1,706 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>xunit.extensions</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="T:Xunit.Extensions.Assertions">
|
||||
<summary>
|
||||
A wrapper for Assert which is used by <see cref="T:Xunit.Extensions.TestClass"/>.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Contains``1(``0,System.Collections.Generic.IEnumerable{``0})">
|
||||
<summary>
|
||||
Verifies that a collection contains a given object.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the object to be verified</typeparam>
|
||||
<param name="expected">The object expected to be in the collection</param>
|
||||
<param name="collection">The collection to be inspected</param>
|
||||
<exception cref="T:Xunit.Sdk.ContainsException">Thrown when the object is not present in the collection</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Contains``1(``0,System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IComparer{``0})">
|
||||
<summary>
|
||||
Verifies that a collection contains a given object, using a comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the object to be verified</typeparam>
|
||||
<param name="expected">The object expected to be in the collection</param>
|
||||
<param name="collection">The collection to be inspected</param>
|
||||
<param name="comparer">The comparer used to equate objects in the collection with the expected object</param>
|
||||
<exception cref="T:Xunit.Sdk.ContainsException">Thrown when the object is not present in the collection</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Contains(System.String,System.String)">
|
||||
<summary>
|
||||
Verifies that a string contains a given sub-string, using the current culture.
|
||||
</summary>
|
||||
<param name="expectedSubString">The sub-string expected to be in the string</param>
|
||||
<param name="actualString">The string to be inspected</param>
|
||||
<exception cref="T:Xunit.Sdk.ContainsException">Thrown when the sub-string is not present inside the string</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Contains(System.String,System.String,System.StringComparison)">
|
||||
<summary>
|
||||
Verifies that a string contains a given sub-string, using the given comparison type.
|
||||
</summary>
|
||||
<param name="expectedSubString">The sub-string expected to be in the string</param>
|
||||
<param name="actualString">The string to be inspected</param>
|
||||
<param name="comparisonType">The type of string comparison to perform</param>
|
||||
<exception cref="T:Xunit.Sdk.ContainsException">Thrown when the sub-string is not present inside the string</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.DoesNotContain``1(``0,System.Collections.Generic.IEnumerable{``0})">
|
||||
<summary>
|
||||
Verifies that a collection does not contain a given object.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the object to be compared</typeparam>
|
||||
<param name="expected">The object that is expected not to be in the collection</param>
|
||||
<param name="collection">The collection to be inspected</param>
|
||||
<exception cref="T:Xunit.Sdk.DoesNotContainException">Thrown when the object is present inside the container</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.DoesNotContain``1(``0,System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IComparer{``0})">
|
||||
<summary>
|
||||
Verifies that a collection does not contain a given object, using a comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the object to be compared</typeparam>
|
||||
<param name="expected">The object that is expected not to be in the collection</param>
|
||||
<param name="collection">The collection to be inspected</param>
|
||||
<param name="comparer">The comparer used to equate objects in the collection with the expected object</param>
|
||||
<exception cref="T:Xunit.Sdk.DoesNotContainException">Thrown when the object is present inside the container</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.DoesNotContain(System.String,System.String)">
|
||||
<summary>
|
||||
Verifies that a string does not contain a given sub-string, using the current culture.
|
||||
</summary>
|
||||
<param name="expectedSubString">The sub-string which is expected not to be in the string</param>
|
||||
<param name="actualString">The string to be inspected</param>
|
||||
<exception cref="T:Xunit.Sdk.DoesNotContainException">Thrown when the sub-string is present inside the string</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.DoesNotContain(System.String,System.String,System.StringComparison)">
|
||||
<summary>
|
||||
Verifies that a string does not contain a given sub-string, using the current culture.
|
||||
</summary>
|
||||
<param name="expectedSubString">The sub-string which is expected not to be in the string</param>
|
||||
<param name="actualString">The string to be inspected</param>
|
||||
<param name="comparisonType">The type of string comparison to perform</param>
|
||||
<exception cref="T:Xunit.Sdk.DoesNotContainException">Thrown when the sub-string is present inside the given string</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.DoesNotThrow(Xunit.Assert.ThrowsDelegate)">
|
||||
<summary>
|
||||
Verifies that a block of code does not throw any exceptions.
|
||||
</summary>
|
||||
<param name="testCode">A delegate to the code to be tested</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Empty(System.Collections.IEnumerable)">
|
||||
<summary>
|
||||
Verifies that a collection is empty.
|
||||
</summary>
|
||||
<param name="collection">The collection to be inspected</param>
|
||||
<exception cref="T:System.ArgumentNullException">Thrown when the collection is null</exception>
|
||||
<exception cref="T:Xunit.Sdk.EmptyException">Thrown when the collection is not empty</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Equal``1(``0,``0)">
|
||||
<summary>
|
||||
Verifies that two objects are equal, using a default comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the objects to be compared</typeparam>
|
||||
<param name="expected">The expected value</param>
|
||||
<param name="actual">The value to be compared against</param>
|
||||
<exception cref="T:Xunit.Sdk.EqualException">Thrown when the objects are not equal</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Equal``1(``0,``0,System.Collections.Generic.IComparer{``0})">
|
||||
<summary>
|
||||
Verifies that two objects are equal, using a custom comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the objects to be compared</typeparam>
|
||||
<param name="expected">The expected value</param>
|
||||
<param name="actual">The value to be compared against</param>
|
||||
<param name="comparer">The comparer used to compare the two objects</param>
|
||||
<exception cref="T:Xunit.Sdk.EqualException">Thrown when the objects are not equal</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Equals(System.Object)">
|
||||
<summary>Do not call this method. Call Assert.Equal() instead.</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.False(System.Boolean)">
|
||||
<summary>
|
||||
Verifies that the condition is false.
|
||||
</summary>
|
||||
<param name="condition">The condition to be tested</param>
|
||||
<exception cref="T:Xunit.Sdk.FalseException">Thrown if the condition is not false</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.False(System.Boolean,System.String)">
|
||||
<summary>
|
||||
Verifies that the condition is false.
|
||||
</summary>
|
||||
<param name="condition">The condition to be tested</param>
|
||||
<param name="userMessage">The message to show when the condition is not false</param>
|
||||
<exception cref="T:Xunit.Sdk.FalseException">Thrown if the condition is not false</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.GetHashCode">
|
||||
<summary>
|
||||
Serves as a hash function for a particular type.
|
||||
</summary>
|
||||
<returns>A hash code for the current <see cref="T:System.Object"/>.</returns>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.InRange``1(``0,``0,``0)">
|
||||
<summary>
|
||||
Verifies that a value is within a given range.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the value to be compared</typeparam>
|
||||
<param name="actual">The actual value to be evaluated</param>
|
||||
<param name="low">The (inclusive) low value of the range</param>
|
||||
<param name="high">The (inclusive) high value of the range</param>
|
||||
<exception cref="T:Xunit.Sdk.InRangeException">Thrown when the value is not in the given range</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.InRange``1(``0,``0,``0,System.Collections.Generic.IComparer{``0})">
|
||||
<summary>
|
||||
Verifies that a value is within a given range, using a comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the value to be compared</typeparam>
|
||||
<param name="actual">The actual value to be evaluated</param>
|
||||
<param name="low">The (inclusive) low value of the range</param>
|
||||
<param name="high">The (inclusive) high value of the range</param>
|
||||
<param name="comparer">The comparer used to evaluate the value's range</param>
|
||||
<exception cref="T:Xunit.Sdk.InRangeException">Thrown when the value is not in the given range</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.IsNotType``1(System.Object)">
|
||||
<summary>
|
||||
Verifies that an object is not exactly the given type.
|
||||
</summary>
|
||||
<typeparam name="T">The type the object should not be</typeparam>
|
||||
<param name="object">The object to be evaluated</param>
|
||||
<exception cref="T:Xunit.Sdk.IsTypeException">Thrown when the object is the given type</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.IsNotType(System.Type,System.Object)">
|
||||
<summary>
|
||||
Verifies that an object is not exactly the given type.
|
||||
</summary>
|
||||
<param name="expectedType">The type the object should not be</param>
|
||||
<param name="object">The object to be evaluated</param>
|
||||
<exception cref="T:Xunit.Sdk.IsTypeException">Thrown when the object is the given type</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.IsType``1(System.Object)">
|
||||
<summary>
|
||||
Verifies that an object is exactly the given type (and not a derived type).
|
||||
</summary>
|
||||
<typeparam name="T">The type the object should be</typeparam>
|
||||
<param name="object">The object to be evaluated</param>
|
||||
<returns>The object, casted to type T when successful</returns>
|
||||
<exception cref="T:Xunit.Sdk.IsTypeException">Thrown when the object is not the given type</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.IsType(System.Type,System.Object)">
|
||||
<summary>
|
||||
Verifies that an object is exactly the given type (and not a derived type).
|
||||
</summary>
|
||||
<param name="expectedType">The type the object should be</param>
|
||||
<param name="object">The object to be evaluated</param>
|
||||
<exception cref="T:Xunit.Sdk.IsTypeException">Thrown when the object is not the given type</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotEmpty(System.Collections.IEnumerable)">
|
||||
<summary>
|
||||
Verifies that a collection is not empty.
|
||||
</summary>
|
||||
<param name="collection">The collection to be inspected</param>
|
||||
<exception cref="T:System.ArgumentNullException">Thrown when a null collection is passed</exception>
|
||||
<exception cref="T:Xunit.Sdk.NotEmptyException">Thrown when the collection is empty</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotEqual``1(``0,``0)">
|
||||
<summary>
|
||||
Verifies that two objects are not equal, using a default comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the objects to be compared</typeparam>
|
||||
<param name="expected">The expected object</param>
|
||||
<param name="actual">The actual object</param>
|
||||
<exception cref="T:Xunit.Sdk.NotEqualException">Thrown when the objects are equal</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotEqual``1(``0,``0,System.Collections.Generic.IComparer{``0})">
|
||||
<summary>
|
||||
Verifies that two objects are not equal, using a custom comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the objects to be compared</typeparam>
|
||||
<param name="expected">The expected object</param>
|
||||
<param name="actual">The actual object</param>
|
||||
<param name="comparer">The comparer used to examine the objects</param>
|
||||
<exception cref="T:Xunit.Sdk.NotEqualException">Thrown when the objects are equal</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotInRange``1(``0,``0,``0)">
|
||||
<summary>
|
||||
Verifies that a value is not within a given range, using the default comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the value to be compared</typeparam>
|
||||
<param name="actual">The actual value to be evaluated</param>
|
||||
<param name="low">The (inclusive) low value of the range</param>
|
||||
<param name="high">The (inclusive) high value of the range</param>
|
||||
<exception cref="T:Xunit.Sdk.NotInRangeException">Thrown when the value is in the given range</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotInRange``1(``0,``0,``0,System.Collections.Generic.IComparer{``0})">
|
||||
<summary>
|
||||
Verifies that a value is not within a given range, using a comparer.
|
||||
</summary>
|
||||
<typeparam name="T">The type of the value to be compared</typeparam>
|
||||
<param name="actual">The actual value to be evaluated</param>
|
||||
<param name="low">The (inclusive) low value of the range</param>
|
||||
<param name="high">The (inclusive) high value of the range</param>
|
||||
<param name="comparer">The comparer used to evaluate the value's range</param>
|
||||
<exception cref="T:Xunit.Sdk.NotInRangeException">Thrown when the value is in the given range</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotNull(System.Object)">
|
||||
<summary>
|
||||
Verifies that an object reference is not null.
|
||||
</summary>
|
||||
<param name="object">The object to be validated</param>
|
||||
<exception cref="T:Xunit.Sdk.NotNullException">Thrown when the object is not null</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.NotSame(System.Object,System.Object)">
|
||||
<summary>
|
||||
Verifies that two objects are not the same instance.
|
||||
</summary>
|
||||
<param name="expected">The expected object instance</param>
|
||||
<param name="actual">The actual object instance</param>
|
||||
<exception cref="T:Xunit.Sdk.NotSameException">Thrown when the objects are the same instance</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Null(System.Object)">
|
||||
<summary>
|
||||
Verifies that an object reference is null.
|
||||
</summary>
|
||||
<param name="object">The object to be inspected</param>
|
||||
<exception cref="T:Xunit.Sdk.NullException">Thrown when the object reference is not null</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Same(System.Object,System.Object)">
|
||||
<summary>
|
||||
Verifies that two objects are the same instance.
|
||||
</summary>
|
||||
<param name="expected">The expected object instance</param>
|
||||
<param name="actual">The actual object instance</param>
|
||||
<exception cref="T:Xunit.Sdk.SameException">Thrown when the objects are not the same instance</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Throws``1(Xunit.Assert.ThrowsDelegate)">
|
||||
<summary>
|
||||
Verifies that the exact exception is thrown (and not a derived exception type).
|
||||
</summary>
|
||||
<typeparam name="T">The type of the exception expected to be thrown</typeparam>
|
||||
<param name="testCode">A delegate to the code to be tested</param>
|
||||
<returns>The exception that was thrown, when successful</returns>
|
||||
<exception cref="T:Xunit.Sdk.ThrowsException">Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Throws``1(System.String,Xunit.Assert.ThrowsDelegate)">
|
||||
<summary>
|
||||
Verifies that the exact exception is thrown (and not a derived exception type).
|
||||
</summary>
|
||||
<typeparam name="T">The type of the exception expected to be thrown</typeparam>
|
||||
<param name="userMessage">The message to be shown if the test fails</param>
|
||||
<param name="testCode">A delegate to the code to be tested</param>
|
||||
<returns>The exception that was thrown, when successful</returns>
|
||||
<exception cref="T:Xunit.Sdk.ThrowsException">Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.Throws(System.Type,Xunit.Assert.ThrowsDelegate)">
|
||||
<summary>
|
||||
Verifies that the exact exception is thrown (and not a derived exception type).
|
||||
</summary>
|
||||
<param name="exceptionType">The type of the exception expected to be thrown</param>
|
||||
<param name="testCode">A delegate to the code to be tested</param>
|
||||
<returns>The exception that was thrown, when successful</returns>
|
||||
<exception cref="T:Xunit.Sdk.ThrowsException">Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.True(System.Boolean)">
|
||||
<summary>
|
||||
Verifies that an expression is true.
|
||||
</summary>
|
||||
<param name="condition">The condition to be inspected</param>
|
||||
<exception cref="T:Xunit.Sdk.TrueException">Thrown when the condition is false</exception>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Assertions.True(System.Boolean,System.String)">
|
||||
<summary>
|
||||
Verifies that an expression is true.
|
||||
</summary>
|
||||
<param name="condition">The condition to be inspected</param>
|
||||
<param name="userMessage">The message to be shown when the condition is false</param>
|
||||
<exception cref="T:Xunit.Sdk.TrueException">Thrown when the condition is false</exception>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.TestClass">
|
||||
<summary>
|
||||
A class which can be derived from for test classes, which bring an overridable version
|
||||
of Assert (using the <see cref="T:Xunit.Extensions.Assertions"/> class.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.TestClass.Assert">
|
||||
<summary>
|
||||
Gets a class which provides assertions.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.AssumeIdentityAttribute">
|
||||
<summary>
|
||||
Apply this attribute to your test method to replace the
|
||||
<see cref="P:System.Threading.Thread.CurrentPrincipal"/> with another role.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.AssumeIdentityAttribute.#ctor(System.String)">
|
||||
<summary>
|
||||
Replaces the identity of the current thread with <paramref name="name"/>.
|
||||
</summary>
|
||||
<param name="name">The role's name</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.AssumeIdentityAttribute.After(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
Restores the original <see cref="P:System.Threading.Thread.CurrentPrincipal"/>.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method under test</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.AssumeIdentityAttribute.Before(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
Stores the current <see cref="P:System.Threading.Thread.CurrentPrincipal"/> and replaces it with
|
||||
a new role identified in constructor.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method under test</param>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.AutoRollbackAttribute">
|
||||
<summary>
|
||||
Apply this attribute to your test method to automatically create a
|
||||
<see cref="T:System.Transactions.TransactionScope"/> that is rolled back when the test is
|
||||
finished.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.AutoRollbackAttribute.After(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
Rolls back the transaction.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.AutoRollbackAttribute.Before(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
Creates the transaction.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.AutoRollbackAttribute.IsolationLevel">
|
||||
<summary>
|
||||
Gets or sets the isolation level of the transaction.
|
||||
Default value is <see cref="P:Xunit.Extensions.AutoRollbackAttribute.IsolationLevel"/>.Unspecified.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.AutoRollbackAttribute.ScopeOption">
|
||||
<summary>
|
||||
Gets or sets the scope option for the transaction.
|
||||
Default value is <see cref="T:System.Transactions.TransactionScopeOption"/>.Required.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.AutoRollbackAttribute.TimeoutInMS">
|
||||
<summary>
|
||||
Gets or sets the timeout of the transaction, in milliseconds.
|
||||
By default, the transaction will not timeout.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.ClassDataAttribute">
|
||||
<summary>
|
||||
Provides a data source for a data theory, with the data coming from a class
|
||||
which must implement IEnumerable<object[]>.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.DataAttribute">
|
||||
<summary>
|
||||
Abstract attribute which represents a data source for a data theory.
|
||||
Data source providers derive from this attribute and implement GetData
|
||||
to return the data for the theory.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.DataAttribute.GetData(System.Reflection.MethodInfo,System.Type[])">
|
||||
<summary>
|
||||
Returns the data to be used to test the theory.
|
||||
</summary>
|
||||
<remarks>
|
||||
The <paramref name="parameterTypes"/> parameter is provided so that the
|
||||
test data can be converted to the destination parameter type when necessary.
|
||||
Generally, data should NOT be automatically converted, UNLESS the source data
|
||||
format does not have rich types (for example, all numbers in Excel spreadsheets
|
||||
are returned as <see cref="T:System.Double"/> even if they are integers). Derivers of
|
||||
this class should NOT throw exceptions for mismatched types or mismatched number
|
||||
of parameters; the test framework will throw these exceptions at the correct
|
||||
time.
|
||||
</remarks>
|
||||
<param name="methodUnderTest">The method that is being tested</param>
|
||||
<param name="parameterTypes">The types of the parameters for the test method</param>
|
||||
<returns>The theory data</returns>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.ClassDataAttribute.#ctor(System.Type)">
|
||||
<summary>
|
||||
Initializes a new instance of the <see cref="T:Xunit.Extensions.ClassDataAttribute"/> class.
|
||||
</summary>
|
||||
<param name="class">The class that provides the data.</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.ClassDataAttribute.GetData(System.Reflection.MethodInfo,System.Type[])">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.DataAdapterDataAttribute">
|
||||
<summary>
|
||||
Represents an implementation of <see cref="T:Xunit.Extensions.DataAttribute"/> which uses an
|
||||
instance of <see cref="T:System.Data.IDataAdapter"/> to get the data for a <see cref="T:Xunit.Extensions.TheoryAttribute"/>
|
||||
decorated test method.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.DataAdapterDataAttribute.GetData(System.Reflection.MethodInfo,System.Type[])">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.DataAdapterDataAttribute.ConvertParameter(System.Object,System.Type)">
|
||||
<summary>
|
||||
Converts a parameter to its destination parameter type, if necessary.
|
||||
</summary>
|
||||
<param name="parameter">The parameter value</param>
|
||||
<param name="parameterType">The destination parameter type (null if not known)</param>
|
||||
<returns>The converted parameter value</returns>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.DataAdapterDataAttribute.DataAdapter">
|
||||
<summary>
|
||||
Gets the data adapter to be used to retrieve the test data.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.InlineDataAttribute">
|
||||
<summary>
|
||||
Provides a data source for a data theory, with the data coming from inline values.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.InlineDataAttribute.#ctor(System.Object[])">
|
||||
<summary>
|
||||
Initializes a new instance of the <see cref="T:Xunit.Extensions.InlineDataAttribute"/> class.
|
||||
</summary>
|
||||
<param name="dataValues">The data values to pass to the theory</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.InlineDataAttribute.GetData(System.Reflection.MethodInfo,System.Type[])">
|
||||
<summary>
|
||||
Returns the data to be used to test the theory.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method that is being tested</param>
|
||||
<param name="parameterTypes">The types of the parameters for the test method</param>
|
||||
<returns>The theory data, in table form</returns>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.OleDbDataAttribute">
|
||||
<summary>
|
||||
Provides a data source for a data theory, with the data coming from an OLEDB connection.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.OleDbDataAttribute.#ctor(System.String,System.String)">
|
||||
<summary>
|
||||
Creates a new instance of <see cref="T:Xunit.Extensions.OleDbDataAttribute"/>.
|
||||
</summary>
|
||||
<param name="connectionString">The OLEDB connection string to the data</param>
|
||||
<param name="selectStatement">The SELECT statement used to return the data for the theory</param>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.OleDbDataAttribute.DataAdapter">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.PropertyDataAttribute">
|
||||
<summary>
|
||||
Provides a data source for a data theory, with the data coming from a public static property on the test class.
|
||||
The property must return IEnumerable<object[]> with the test data.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.PropertyDataAttribute.#ctor(System.String)">
|
||||
<summary>
|
||||
Creates a new instance of <see cref="T:Xunit.Extensions.PropertyDataAttribute"/>/
|
||||
</summary>
|
||||
<param name="propertyName">The name of the public static property on the test class that will provide the test data</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.PropertyDataAttribute.GetData(System.Reflection.MethodInfo,System.Type[])">
|
||||
<summary>
|
||||
Returns the data to be used to test the theory.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method that is being tested</param>
|
||||
<param name="parameterTypes">The types of the parameters for the test method</param>
|
||||
<returns>The theory data, in table form</returns>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.SqlServerDataAttribute">
|
||||
<summary>
|
||||
Provides a data source for a data theory, with the data coming a Microsoft SQL Server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.SqlServerDataAttribute.#ctor(System.String,System.String,System.String)">
|
||||
<summary>
|
||||
Creates a new instance of <see cref="T:Xunit.Extensions.SqlServerDataAttribute"/>, using a trusted connection.
|
||||
</summary>
|
||||
<param name="serverName">The server name of the Microsoft SQL Server</param>
|
||||
<param name="databaseName">The database name</param>
|
||||
<param name="selectStatement">The SQL SELECT statement to return the data for the data theory</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.SqlServerDataAttribute.#ctor(System.String,System.String,System.String,System.String,System.String)">
|
||||
<summary>
|
||||
Creates a new instance of <see cref="T:Xunit.Extensions.SqlServerDataAttribute"/>, using the provided username and password.
|
||||
</summary>
|
||||
<param name="serverName">The server name of the Microsoft SQL Server</param>
|
||||
<param name="databaseName">The database name</param>
|
||||
<param name="username">The username for the server</param>
|
||||
<param name="password">The password for the server</param>
|
||||
<param name="selectStatement">The SQL SELECT statement to return the data for the data theory</param>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.ExcelDataAttribute">
|
||||
<summary>
|
||||
Provides a data source for a data theory, with the data coming a Microsoft Excel (.xls) spreadsheet.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.ExcelDataAttribute.#ctor(System.String,System.String)">
|
||||
<summary>
|
||||
Creates a new instance of <see cref="T:Xunit.Extensions.ExcelDataAttribute"/>.
|
||||
</summary>
|
||||
<param name="filename">The filename of the XLS spreadsheet file; if the filename provided
|
||||
is relative, then it is relative to the location of xunit.extensions.dll.</param>
|
||||
<param name="selectStatement">The SELECT statement that returns the data for the theory</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.ExcelDataAttribute.ConvertParameter(System.Object,System.Type)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.Clock">
|
||||
<summary>
|
||||
A wrapper around the static operations on <see cref="T:System.DateTime"/> which allows time
|
||||
to be frozen using the <see cref="T:Xunit.Extensions.FreezeClockAttribute"/>. The clock begins in the
|
||||
thawed state; that is, calls to <see cref="P:Xunit.Extensions.Clock.Now"/>, <see cref="P:Xunit.Extensions.Clock.Today"/>, and
|
||||
<see cref="P:Xunit.Extensions.Clock.UtcNow"/> return current (non-frozen) values.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Clock.Freeze">
|
||||
<summary>
|
||||
Freezes the clock with the current time.
|
||||
Until <see cref="M:Xunit.Extensions.Clock.Thaw"/> is called, all calls to <see cref="P:Xunit.Extensions.Clock.Now"/>, <see cref="P:Xunit.Extensions.Clock.Today"/>, and
|
||||
<see cref="P:Xunit.Extensions.Clock.UtcNow"/> will return the exact same values.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Clock.FreezeLocal(System.DateTime)">
|
||||
<summary>
|
||||
Freezes the clock with the given date and time, considered to be local time.
|
||||
Until <see cref="M:Xunit.Extensions.Clock.Thaw"/> is called, all calls to <see cref="P:Xunit.Extensions.Clock.Now"/>, <see cref="P:Xunit.Extensions.Clock.Today"/>, and
|
||||
<see cref="P:Xunit.Extensions.Clock.UtcNow"/> will return the exact same values.
|
||||
</summary>
|
||||
<param name="localDateTime">The local date and time to freeze to</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Clock.FreezeUtc(System.DateTime)">
|
||||
<summary>
|
||||
Freezes the clock with the given date and time, considered to be Coordinated Universal Time (UTC).
|
||||
Until <see cref="M:Xunit.Extensions.Clock.Thaw"/> is called, all calls to <see cref="P:Xunit.Extensions.Clock.Now"/>, <see cref="P:Xunit.Extensions.Clock.Today"/>, and
|
||||
<see cref="P:Xunit.Extensions.Clock.UtcNow"/> will return the exact same values.
|
||||
</summary>
|
||||
<param name="utcDateTime">The UTC date and time to freeze to</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.Clock.Thaw">
|
||||
<summary>
|
||||
Thaws the clock so that <see cref="P:Xunit.Extensions.Clock.Now"/>, <see cref="P:Xunit.Extensions.Clock.Today"/>, and <see cref="P:Xunit.Extensions.Clock.UtcNow"/>
|
||||
return normal values.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.Clock.Now">
|
||||
<summary>
|
||||
Gets a <see cref="T:System.DateTime"/> object that is set to the current date and time on this computer,
|
||||
expressed as the local time.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.Clock.Today">
|
||||
<summary>
|
||||
Gets the current date.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.Clock.UtcNow">
|
||||
<summary>
|
||||
Gets a <see cref="T:System.DateTime"/> object that is set to the current date and time on this computer,
|
||||
expressed as the Coordinated Universal Time (UTC).
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.FreezeClockAttribute">
|
||||
<summary>
|
||||
Apply this attribute to your test method to freeze the time represented by the
|
||||
<see cref="T:Xunit.Extensions.Clock"/> class.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.FreezeClockAttribute.#ctor">
|
||||
<summary>
|
||||
Freeze the clock with the current date and time.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.FreezeClockAttribute.#ctor(System.Int32,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
Freeze the clock with the given date, considered to be local time.
|
||||
</summary>
|
||||
<param name="year">The frozen year</param>
|
||||
<param name="month">The frozen month</param>
|
||||
<param name="day">The frozen day</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.FreezeClockAttribute.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
Freeze the clock with the given date and time, considered to be in local time.
|
||||
</summary>
|
||||
<param name="year">The frozen year</param>
|
||||
<param name="month">The frozen month</param>
|
||||
<param name="day">The frozen day</param>
|
||||
<param name="hour">The frozen hour</param>
|
||||
<param name="minute">The frozen minute</param>
|
||||
<param name="second">The frozen second</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.FreezeClockAttribute.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.DateTimeKind)">
|
||||
<summary>
|
||||
Freeze the clock with the given date and time, with the given kind of time.
|
||||
</summary>
|
||||
<param name="year">The frozen year</param>
|
||||
<param name="month">The frozen month</param>
|
||||
<param name="day">The frozen day</param>
|
||||
<param name="hour">The frozen hour</param>
|
||||
<param name="minute">The frozen minute</param>
|
||||
<param name="second">The frozen second</param>
|
||||
<param name="kind">The frozen time kind</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.FreezeClockAttribute.After(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
Thaws the clock.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method under test</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.FreezeClockAttribute.Before(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
Freezes the clock.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method under test</param>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.TheoryAttribute">
|
||||
<summary>
|
||||
Marks a test method as being a data theory. Data theories are tests which are fed
|
||||
various bits of data from a data source, mapping to parameters on the test method.
|
||||
If the data source contains multiple rows, then the test method is executed
|
||||
multiple times (once with each data row).
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.TheoryAttribute.EnumerateTestCommands(Xunit.Sdk.IMethodInfo)">
|
||||
<summary>
|
||||
Creates instances of <see cref="T:Xunit.Extensions.TheoryCommand"/> which represent individual intended
|
||||
invocations of the test method, one per data row in the data source.
|
||||
</summary>
|
||||
<param name="method">The method under test</param>
|
||||
<returns>An enumerator through the desired test method invocations</returns>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.TheoryCommand">
|
||||
<summary>
|
||||
Represents a single invocation of a data theory test method.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.TheoryCommand.#ctor(Xunit.Sdk.IMethodInfo,System.String,System.Object[])">
|
||||
<summary>
|
||||
Creates a new instance of <see cref="T:Xunit.Extensions.TheoryCommand"/>.
|
||||
</summary>
|
||||
<param name="testMethod">The method under test</param>
|
||||
<param name="displayName">The display name of the method under test</param>
|
||||
<param name="parameters">The parameters to be passed to the test method</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.TheoryCommand.Execute(System.Object)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="P:Xunit.Extensions.TheoryCommand.Parameters">
|
||||
<summary>
|
||||
Gets the parameter values that are passed to the test method.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Xunit.Extensions.TraceAttribute">
|
||||
<summary>
|
||||
Apply to a test method to trace the method begin and end.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.TraceAttribute.Before(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
This method is called before the test method is executed.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method under test</param>
|
||||
</member>
|
||||
<member name="M:Xunit.Extensions.TraceAttribute.After(System.Reflection.MethodInfo)">
|
||||
<summary>
|
||||
This method is called after the test method is executed.
|
||||
</summary>
|
||||
<param name="methodUnderTest">The method under test</param>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,15 +0,0 @@
|
|||
namespace ColorCode
|
||||
{
|
||||
public static class AcceptanceHelper
|
||||
{
|
||||
const string baseExpectedFormat = @"<div style=""color:Black;background-color:White;""><pre>
|
||||
{0}
|
||||
</pre></div>";
|
||||
|
||||
public static string BuildExpected(string format, params object[] args)
|
||||
{
|
||||
var expectedFormat = string.Format(baseExpectedFormat, format);
|
||||
return string.Format(expectedFormat, args);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,303 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{B25E2B63-11CB-4F5C-AADE-99278AC8DCAC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ColorCode</RootNamespace>
|
||||
<AssemblyName>ColorCode.AcceptanceTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="xunit, Version=1.5.0.1479, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParty\xunit\xunit.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.extensions, Version=1.5.0.1479, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParty\xunit\xunit.extensions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AcceptanceHelper.cs" />
|
||||
<Compile Include="ColorizeData.cs" />
|
||||
<Compile Include="ColorizeTests.cs" />
|
||||
<Compile Include="CppAcceptanceTests.cs" />
|
||||
<Compile Include="Data\csharp\abstract-keyword.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<Compile Include="Data\csharp\as-keyword.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<None Include="Data\csharp\assembly-attribute.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Compile Include="Data\csharp\base-keyword.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<None Include="Data\php\sample.source.php">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\csharp\comments.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\csharp\correct-classname.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Compile Include="Data\csharp\linq-keyword.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
<None Include="Data\csharp\strings.source.cs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Data\fsharp\fsharp-tutorial.source.fs">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Compile Include="JavaAcceptanceTests.cs" />
|
||||
<Compile Include="LegacyAcceptanceTests\AsaxAcceptanceTests.cs" />
|
||||
<Compile Include="LegacyAcceptanceTests\AshxAcceptanceTests.cs" />
|
||||
<Compile Include="LegacyAcceptanceTests\AspxAcceptanceTests.cs" />
|
||||
<Compile Include="LegacyAcceptanceTests\AspxCsScenarioTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\AspxVbScenarioTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\CSharpKeywordTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\CSharpScenarioTest.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\CSSAcceptanceTests.cs" />
|
||||
<Compile Include="LegacyAcceptanceTests\HtmlAcceptanceTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\JavaScriptAcceptanceTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlClrTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlConfiigurationFunctionsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlMetadataFunctionsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlPerformanceTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlScenarioTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlSecurityFunctionsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\SqlTextAndImageFunctionsTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\VbDotNetAcceptanceTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LegacyAcceptanceTests\XmlAcceptanceTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ColorCode\ColorCode.csproj">
|
||||
<Project>{37438935-D221-4FD8-A10E-4EC5356B0F94}</Project>
|
||||
<Name>ColorCode</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Data\ashx\simple.source.ashx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Data\css\sample.source.css">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="LegacyAcceptanceTests\large.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Data\asax\class.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\asax\class.source.asax">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Data\ashx\simple.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\csharp\abstract-keyword.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\csharp\as-keyword.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\csharp\assembly-attribute.expected.html" />
|
||||
<Content Include="Data\csharp\base-keyword.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\csharp\comments.expected.html" />
|
||||
<Content Include="Data\csharp\correct-classname.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\csharp\linq-keyword.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Data\csharp\strings.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Data\css\sample.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\fsharp\fsharp-tutorial.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\php\sample.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Data\ps\keywords.source.ps1">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\ps\multilinecomments.source.ps1">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\ps\operators.source.ps1">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\ps\sample.source.ps1" />
|
||||
<None Include="Data\sql\aggregate-functions.source.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\sql\keyword-color.source.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\sql\math-functions.source.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\sql\system-function-color.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\sql\aggregate-functions.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\sql\math-functions.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\sql\keyword-color.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\ps\keywords.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\ps\operators.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="Data\ps\multilinecomments.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\ps\sample.expected.html" />
|
||||
<Content Include="Data\vb\linq-keyword.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\vb\linq-keyword.source.vb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\vb\strings.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Data\vb\strings.source.vb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Data\sql\system-function-color.source.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\xml\xml-stylesheet.expected.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Data\xml\xml-stylesheet.source.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Content Include="LegacyAcceptanceTests\large.html" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -1,77 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using ColorCode.Common;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class ColorizeData : DataAttribute
|
||||
{
|
||||
readonly Regex sourceFileRegex = new Regex(@"(?i)[a-z]+\.source\.([a-z0-9]+)", RegexOptions.Compiled);
|
||||
|
||||
public override IEnumerable<object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes)
|
||||
{
|
||||
List<object[]> colorizeData = new List<object[]>();
|
||||
|
||||
string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
||||
string[] dirNames = Directory.GetDirectories(Path.Combine(appPath, @"..\..\Data"));
|
||||
|
||||
foreach(string dirName in dirNames)
|
||||
{
|
||||
string[] sourceFileNames = Directory.GetFiles(dirName, "*.source.*");
|
||||
|
||||
foreach(string sourceFileName in sourceFileNames)
|
||||
{
|
||||
Match sourceFileMatch = sourceFileRegex.Match(sourceFileName);
|
||||
|
||||
if (sourceFileMatch.Success)
|
||||
{
|
||||
string fileExtension = sourceFileMatch.Groups[1].Captures[0].Value;
|
||||
string languageId = GetLanguageId(fileExtension);
|
||||
|
||||
string expectedFileName = sourceFileName.Replace(".source.", ".expected.").Replace("." + fileExtension, ".html");
|
||||
|
||||
colorizeData.Add(new object[] {languageId, sourceFileName, expectedFileName});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return colorizeData;
|
||||
}
|
||||
|
||||
private static string GetLanguageId(string fileExtension)
|
||||
{
|
||||
switch (fileExtension)
|
||||
{
|
||||
case "asax":
|
||||
return LanguageId.Asax;
|
||||
case "ashx":
|
||||
return LanguageId.Ashx;
|
||||
case "cs":
|
||||
return LanguageId.CSharp;
|
||||
case "php":
|
||||
return LanguageId.Php;
|
||||
case "css":
|
||||
return LanguageId.Css;
|
||||
case "vb":
|
||||
return LanguageId.VbDotNet;
|
||||
case "sql":
|
||||
return LanguageId.Sql;
|
||||
case "xml":
|
||||
return LanguageId.Xml;
|
||||
case "ps1":
|
||||
return LanguageId.PowerShell;
|
||||
case "ts":
|
||||
return LanguageId.TypeScript;
|
||||
case "fs":
|
||||
return LanguageId.FSharp;
|
||||
default:
|
||||
throw new ArgumentException(string.Format("Unexpected file extension: {0}.", fileExtension));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
using System.IO;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class ColorizeTests
|
||||
{
|
||||
[Theory]
|
||||
[ColorizeData]
|
||||
public void ColorCode_will_colorize_source_code(string languageId, string sourceFileName, string expectedFileName)
|
||||
{
|
||||
ILanguage language = Languages.FindById(languageId);
|
||||
string sourceCode = File.ReadAllText(sourceFileName);
|
||||
string expectedHtml = File.ReadAllText(expectedFileName);
|
||||
|
||||
string actualHtml = new CodeColorizer().Colorize(sourceCode, language);
|
||||
File.WriteAllText(expectedFileName.Replace(".expected.", ".actual."), actualHtml);
|
||||
|
||||
Assert.Equal(expectedHtml, actualHtml);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,211 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class CppAcceptanceTests
|
||||
{
|
||||
public class CommentTests
|
||||
{
|
||||
[Fact]
|
||||
public void WillColorizeACommentOnMultipleLines()
|
||||
{
|
||||
const string source = @"/*
|
||||
comment line
|
||||
comment line 2
|
||||
*/";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">/*
|
||||
comment line
|
||||
comment line 2
|
||||
*/</span>");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillColorizeAMultieLineStyleCommentOnOneLine()
|
||||
{
|
||||
const string source = @"/*comment*/";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">/*comment*/</span>");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillColorizeASingleLineStyleComment()
|
||||
{
|
||||
const string source = @"//comment";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">//comment</span>");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public class StringTests
|
||||
{
|
||||
[Fact]
|
||||
public void WillColorizeStrings()
|
||||
{
|
||||
const string source = @"string aString = ""aString"";";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"string aString = <span style=""color:#A31515;"">"aString"</span>;");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public class KeywordTests
|
||||
{
|
||||
[Theory]
|
||||
[CppKeywordData]
|
||||
public void WillColorizeAKeywordWithNoSurroundingText(string keyword)
|
||||
{
|
||||
var source = keyword;
|
||||
var exepected = AcceptanceHelper.BuildExpected(@"<span style=""color:Blue;"">{0}</span>", keyword);
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(exepected, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CppKeywordData]
|
||||
public void WillColorizeAKeywordWithPrecedingAndSucceedingText(string keyword)
|
||||
{
|
||||
var source = string.Format("fnord {0} fnord", keyword);
|
||||
var exepected = AcceptanceHelper.BuildExpected(@"fnord <span style=""color:Blue;"">{0}</span> fnord", keyword);
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(exepected, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[CppKeywordData]
|
||||
public void WillNotColorizeAKeywordInsideAWord(string keyword)
|
||||
{
|
||||
var source = string.Format("fnord{0}fnord", keyword);
|
||||
var exepected = AcceptanceHelper.BuildExpected(@"fnord{0}fnord", keyword);
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
|
||||
|
||||
Assert.Equal(exepected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Theory Data
|
||||
public class CppKeywordData : DataAttribute
|
||||
{
|
||||
public override IEnumerable<object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes)
|
||||
{
|
||||
var keywordData = new List<object[]>
|
||||
{
|
||||
new object[] {"abstract"},
|
||||
new object[] {"array"},
|
||||
new object[] {"auto"},
|
||||
new object[] {"bool"},
|
||||
new object[] {"break"},
|
||||
new object[] {"case"},
|
||||
new object[] {"catch"},
|
||||
new object[] {"char"},
|
||||
new object[] {"class"},
|
||||
new object[] {"const"},
|
||||
new object[] {"const_cast"},
|
||||
new object[] {"continue"},
|
||||
new object[] {"default"},
|
||||
new object[] {"delegate"},
|
||||
new object[] {"delete"},
|
||||
new object[] {"deprecated"},
|
||||
new object[] {"dllexport"},
|
||||
new object[] {"dllimport"},
|
||||
new object[] {"do"},
|
||||
new object[] {"double"},
|
||||
new object[] {"dynamic_cast"},
|
||||
new object[] {"each"},
|
||||
new object[] {"else"},
|
||||
new object[] {"enum"},
|
||||
new object[] {"event"},
|
||||
new object[] {"explicit"},
|
||||
new object[] {"export"},
|
||||
new object[] {"extern"},
|
||||
new object[] {"false"},
|
||||
new object[] {"float"},
|
||||
new object[] {"for"},
|
||||
new object[] {"friend"},
|
||||
new object[] {"friend_as"},
|
||||
new object[] {"gcnew"},
|
||||
new object[] {"generic"},
|
||||
new object[] {"goto"},
|
||||
new object[] {"if"},
|
||||
new object[] {"in"},
|
||||
new object[] {"initonly"},
|
||||
new object[] {"inline"},
|
||||
new object[] {"int"},
|
||||
new object[] {"interface"},
|
||||
new object[] {"literal"},
|
||||
new object[] {"long"},
|
||||
new object[] {"mutable"},
|
||||
new object[] {"naked"},
|
||||
new object[] {"namespace"},
|
||||
new object[] {"new"},
|
||||
new object[] {"noinline"},
|
||||
new object[] {"noreturn"},
|
||||
new object[] {"nothrow"},
|
||||
new object[] {"novtable"},
|
||||
new object[] {"nullptr"},
|
||||
new object[] {"operator"},
|
||||
new object[] {"private"},
|
||||
new object[] {"property"},
|
||||
new object[] {"protected"},
|
||||
new object[] {"public"},
|
||||
new object[] {"ref class"},
|
||||
new object[] {"ref struct"},
|
||||
new object[] {"register"},
|
||||
new object[] {"reinterpret_cast"},
|
||||
new object[] {"return"},
|
||||
new object[] {"safecast"},
|
||||
new object[] {"sealed"},
|
||||
new object[] {"selectany"},
|
||||
new object[] {"short"},
|
||||
new object[] {"signed"},
|
||||
new object[] {"sizeof"},
|
||||
new object[] {"static"},
|
||||
new object[] {"static_cast"},
|
||||
new object[] {"struct"},
|
||||
new object[] {"switch"},
|
||||
new object[] {"template"},
|
||||
new object[] {"this"},
|
||||
new object[] {"thread"},
|
||||
new object[] {"throw"},
|
||||
new object[] {"true"},
|
||||
new object[] {"try"},
|
||||
new object[] {"typedef"},
|
||||
new object[] {"typeid"},
|
||||
new object[] {"typename"},
|
||||
new object[] {"union"},
|
||||
new object[] {"unsigned"},
|
||||
new object[] {"using"},
|
||||
new object[] {"uuid"},
|
||||
new object[] {"value"},
|
||||
new object[] {"virtual"},
|
||||
new object[] {"void"},
|
||||
new object[] {"volatile"},
|
||||
new object[] {"wchar_t"},
|
||||
new object[] {"while"},
|
||||
};
|
||||
return keywordData;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="background-color:Yellow;"><%</span><span style="color:Blue;">@</span> <span style="color:#A31515;">Application</span> <span style="color:Red;">Language</span><span style="color:Blue;">=</span><span style="color:Blue;">"C#"</span> <span style="color:Red;">CodeBehind</span><span style="color:Blue;">=</span><span style="color:Blue;">"Global.asax.cs"</span> <span style="color:Red;">Inherits</span><span style="color:Blue;">=</span><span style="color:Blue;">"Microsoft.Foundation.Web.Global"</span> <span style="background-color:Yellow;">%></span>
|
||||
<span style="color:Blue;"><</span><span style="color:#A31515;">script</span> <span style="color:Red;">runat</span><span style="color:Blue;">=</span><span style="color:Blue;">"server"</span><span style="color:Blue;">></span>
|
||||
<span style="color:Blue;">using</span> System.IO;
|
||||
<span style="color:Blue;">using</span> System.Text;
|
||||
<span style="color:Blue;">using</span> System.Web;
|
||||
<span style="color:Blue;">using</span> CodePlex.Common;
|
||||
<span style="color:Blue;">using</span> CodePlex.Presentation.Compression;
|
||||
<span style="color:Blue;">using</span> CodePlex.Presentation.Css.Presenter;
|
||||
<span style="color:Blue;">using</span> CodePlex.Presentation.Navigation;
|
||||
|
||||
<span style="color:Blue;">namespace</span> CodePlex.WebSite.Css
|
||||
{
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"><summary></span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> StyleSheet.ashx parses and delivers css files submitted through the QueryString</span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> It replaces constants described by the css file in the form </span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> </span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> /*{css:ConstantName}*/</span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> </span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> with the correspondingly named AppSetting Key from the containing directory's .config file</span>
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"></summary></span>
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> StyleSheet : IHttpHandler
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">void</span> ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = <span style="color:#A31515;">"text/css"</span>;
|
||||
<span style="color:Blue;">if</span> (context.Request.QueryString[<span style="color:#A31515;">"i"</span>] == <span style="color:Blue;">null</span>)
|
||||
<span style="color:Blue;">return</span>;
|
||||
|
||||
<span style="color:Blue;">string</span>[] cssFiles;
|
||||
cssFiles = css.ToString().Split(<span style="color:#A31515;">','</span>);
|
||||
<span style="color:Blue;">for</span> (<span style="color:Blue;">int</span> i = 0; i < cssFiles.Length; i++)
|
||||
{
|
||||
cssFiles[i] = Path.GetFileName(cssFiles[i].Trim());
|
||||
<span style="color:Blue;">if</span> (!Path.HasExtension(cssFiles[i]))
|
||||
cssFiles[i] = Path.ChangeExtension(cssFiles[i], <span style="color:#A31515;">".css"</span>);
|
||||
}
|
||||
|
||||
<span style="color:Green;">//Cache settings handled in AddHeaderItemsToRequestModule</span>
|
||||
<span style="color:Green;">//bool alreadyCached;</span>
|
||||
<span style="color:Green;">//CompressionUtility.SetCaching(context, cssFiles, out alreadyCached);</span>
|
||||
<span style="color:Green;">//if (alreadyCached)</span>
|
||||
<span style="color:Green;">// return;</span>
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">bool</span> IsReusable
|
||||
{
|
||||
<span style="color:Blue;">get</span> { <span style="color:Blue;">return</span> <span style="color:Blue;">false</span>; }
|
||||
}
|
||||
}
|
||||
}
|
||||
<span style="color:Blue;"></</span><span style="color:#A31515;">script</span><span style="color:Blue;">></span>
|
||||
</pre></div>
|
|
@ -1,51 +0,0 @@
|
|||
<%@ Application Language="C#" CodeBehind="Global.asax.cs" Inherits="Microsoft.Foundation.Web.Global" %>
|
||||
<script runat="server">
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using CodePlex.Common;
|
||||
using CodePlex.Presentation.Compression;
|
||||
using CodePlex.Presentation.Css.Presenter;
|
||||
using CodePlex.Presentation.Navigation;
|
||||
|
||||
namespace CodePlex.WebSite.Css
|
||||
{
|
||||
/// <summary>
|
||||
/// StyleSheet.ashx parses and delivers css files submitted through the QueryString
|
||||
/// It replaces constants described by the css file in the form
|
||||
///
|
||||
/// /*{css:ConstantName}*/
|
||||
///
|
||||
/// with the correspondingly named AppSetting Key from the containing directory's .config file
|
||||
/// </summary>
|
||||
public class StyleSheet : IHttpHandler
|
||||
{
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "text/css";
|
||||
if (context.Request.QueryString["i"] == null)
|
||||
return;
|
||||
|
||||
string[] cssFiles;
|
||||
cssFiles = css.ToString().Split(',');
|
||||
for (int i = 0; i < cssFiles.Length; i++)
|
||||
{
|
||||
cssFiles[i] = Path.GetFileName(cssFiles[i].Trim());
|
||||
if (!Path.HasExtension(cssFiles[i]))
|
||||
cssFiles[i] = Path.ChangeExtension(cssFiles[i], ".css");
|
||||
}
|
||||
|
||||
//Cache settings handled in AddHeaderItemsToRequestModule
|
||||
//bool alreadyCached;
|
||||
//CompressionUtility.SetCaching(context, cssFiles, out alreadyCached);
|
||||
//if (alreadyCached)
|
||||
// return;
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,20 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="background-color:Yellow;"><%</span><span style="color:Blue;">@</span> <span style="color:#A31515;">WebHandler</span> <span style="color:Red;">Language</span><span style="color:Blue;">=</span><span style="color:Blue;">"C#"</span> <span style="color:Red;">Class</span><span style="color:Blue;">=</span><span style="color:Blue;">"Handler"</span> <span style="background-color:Yellow;">%></span>
|
||||
|
||||
<span style="color:Blue;">using</span> System;
|
||||
<span style="color:Blue;">using</span> System.Web;
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> Handler : IHttpHandler
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">void</span> ProcessRequest (HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = <span style="color:#A31515;">"text/plain"</span>;
|
||||
context.Response.Write(<span style="color:#A31515;">"Hello World"</span>);
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">bool</span> IsReusable
|
||||
{
|
||||
<span style="color:Blue;">get</span> { <span style="color:Blue;">return</span> <span style="color:Blue;">false</span>; }
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,18 +0,0 @@
|
|||
<%@ WebHandler Language="C#" Class="Handler" %>
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
public class Handler : IHttpHandler
|
||||
{
|
||||
public void ProcessRequest (HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("Hello World");
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">// abstract_keyword.cs</span>
|
||||
<span style="color:Green;">// Abstract Classes</span>
|
||||
<span style="color:Blue;">using</span> System;
|
||||
<span style="color:Blue;">abstract</span> <span style="color:Blue;">class</span> MyBaseC
|
||||
{
|
||||
<span style="color:Blue;">protected</span> <span style="color:Blue;">int</span> x = 100;
|
||||
<span style="color:Blue;">protected</span> <span style="color:Blue;">int</span> y = 150;
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">abstract</span> <span style="color:Blue;">void</span> MyMethod(); <span style="color:Green;">// Abstract method</span>
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">abstract</span> <span style="color:Blue;">int</span> GetX <span style="color:Green;">// Abstract property</span>
|
||||
{
|
||||
<span style="color:Blue;">get</span>;
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">abstract</span> <span style="color:Blue;">int</span> GetY <span style="color:Green;">// Abstract property</span>
|
||||
{
|
||||
<span style="color:Blue;">get</span>;
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:Blue;">class</span> MyDerivedC : MyBaseC
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">override</span> <span style="color:Blue;">void</span> MyMethod()
|
||||
{
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">override</span> <span style="color:Blue;">int</span> GetX <span style="color:Green;">// overriding property</span>
|
||||
{
|
||||
<span style="color:Blue;">get</span>
|
||||
{
|
||||
<span style="color:Blue;">return</span> x + 10;
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">override</span> <span style="color:Blue;">int</span> GetY <span style="color:Green;">// overriding property</span>
|
||||
{
|
||||
<span style="color:Blue;">get</span>
|
||||
{
|
||||
<span style="color:Blue;">return</span> y + 10;
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">static</span> <span style="color:Blue;">void</span> Main()
|
||||
{
|
||||
MyDerivedC mC = <span style="color:Blue;">new</span> MyDerivedC();
|
||||
mC.MyMethod();
|
||||
Console.WriteLine(<span style="color:#A31515;">"x = {0}, y = {1}"</span>, mC.GetX, mC.GetY);
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,51 +0,0 @@
|
|||
// abstract_keyword.cs
|
||||
// Abstract Classes
|
||||
using System;
|
||||
abstract class MyBaseC
|
||||
{
|
||||
protected int x = 100;
|
||||
protected int y = 150;
|
||||
public abstract void MyMethod(); // Abstract method
|
||||
|
||||
public abstract int GetX // Abstract property
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract int GetY // Abstract property
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
|
||||
class MyDerivedC : MyBaseC
|
||||
{
|
||||
public override void MyMethod()
|
||||
{
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
|
||||
public override int GetX // overriding property
|
||||
{
|
||||
get
|
||||
{
|
||||
return x + 10;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetY // overriding property
|
||||
{
|
||||
get
|
||||
{
|
||||
return y + 10;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
MyDerivedC mC = new MyDerivedC();
|
||||
mC.MyMethod();
|
||||
Console.WriteLine("x = {0}, y = {1}", mC.GetX, mC.GetY);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">// cs_keyword_as.cs</span>
|
||||
<span style="color:Green;">// The as operator</span>
|
||||
<span style="color:Blue;">using</span> System;
|
||||
<span style="color:Blue;">class</span> MyClass1
|
||||
{
|
||||
}
|
||||
|
||||
<span style="color:Blue;">class</span> MyClass2
|
||||
{
|
||||
}
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> IsTest
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">static</span> <span style="color:Blue;">void</span> Main()
|
||||
{
|
||||
<span style="color:Blue;">object</span>[] myObjects = <span style="color:Blue;">new</span> <span style="color:Blue;">object</span>[6]; <span style="color:Green;">/* test comment 1 */</span>
|
||||
myObjects[0] = <span style="color:Blue;">new</span> MyClass1();
|
||||
myObjects[1] = <span style="color:Blue;">new</span> MyClass2();
|
||||
myObjects[2] = <span style="color:#A31515;">"hello"</span>;
|
||||
myObjects[3] = 123;
|
||||
myObjects[4] = 123.4;
|
||||
myObjects[5] = <span style="color:Blue;">null</span>;
|
||||
|
||||
<span style="color:Blue;">for</span> (<span style="color:Blue;">int</span> i = 0; i < myObjects.Length; ++i)
|
||||
{<span style="color:Green;">/* loop it */</span>
|
||||
<span style="color:Blue;">string</span> s = myObjects[i] <span style="color:Blue;">as</span> <span style="color:Blue;">string</span>;
|
||||
Console.Write(<span style="color:#A31515;">"{0}:"</span>, i);
|
||||
<span style="color:Blue;">if</span> (s != <span style="color:Blue;">null</span>)
|
||||
Console.WriteLine(<span style="color:#A31515;">"'"</span> + s + <span style="color:#A31515;">"'"</span>);
|
||||
<span style="color:Blue;">else</span>
|
||||
Console.WriteLine(<span style="color:#A31515;">"not a string"</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,34 +0,0 @@
|
|||
// cs_keyword_as.cs
|
||||
// The as operator
|
||||
using System;
|
||||
class MyClass1
|
||||
{
|
||||
}
|
||||
|
||||
class MyClass2
|
||||
{
|
||||
}
|
||||
|
||||
public class IsTest
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
object[] myObjects = new object[6]; /* test comment 1 */
|
||||
myObjects[0] = new MyClass1();
|
||||
myObjects[1] = new MyClass2();
|
||||
myObjects[2] = "hello";
|
||||
myObjects[3] = 123;
|
||||
myObjects[4] = 123.4;
|
||||
myObjects[5] = null;
|
||||
|
||||
for (int i = 0; i < myObjects.Length; ++i)
|
||||
{/* loop it */
|
||||
string s = myObjects[i] as string;
|
||||
Console.Write("{0}:", i);
|
||||
if (s != null)
|
||||
Console.WriteLine("'" + s + "'");
|
||||
else
|
||||
Console.WriteLine("not a string");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">using</span> System.Reflection;
|
||||
<span style="color:Blue;">using</span> System.Runtime.CompilerServices;
|
||||
<span style="color:Blue;">using</span> System.Runtime.InteropServices;
|
||||
<span style="color:Blue;">using</span> System.Resources;
|
||||
|
||||
<span style="color:Green;">// General Information about an assembly is controlled through the following </span>
|
||||
<span style="color:Green;">// set of attributes. Change these attribute values to modify the information</span>
|
||||
<span style="color:Green;">// associated with an assembly.</span>
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyTitle(<span style="color:#A31515;">"Global"</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyDescription(<span style="color:#A31515;">""</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyConfiguration(<span style="color:#A31515;">""</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyCompany(<span style="color:#A31515;">"Fnord"</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyProduct(<span style="color:#A31515;">"Global"</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyCopyright(<span style="color:#A31515;">"Copyright © Fnord 2010"</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyTrademark(<span style="color:#A31515;">""</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyCulture(<span style="color:#A31515;">""</span>)]
|
||||
|
||||
<span style="color:Green;">// Setting ComVisible to false makes the types in this assembly not visible </span>
|
||||
<span style="color:Green;">// to COM components. If you need to access a type in this assembly from </span>
|
||||
<span style="color:Green;">// COM, set the ComVisible attribute to true on that type.</span>
|
||||
[<span style="color:Blue;">assembly</span>: ComVisible(false)]
|
||||
|
||||
<span style="color:Green;">// The following GUID is for the ID of the typelib if this project is exposed to COM</span>
|
||||
[<span style="color:Blue;">assembly</span>: Guid(<span style="color:#A31515;">"f4fd840f-e0b8-431f-8e32-c58a82baaf36"</span>)]
|
||||
|
||||
<span style="color:Green;">// Version information for an assembly consists of the following four values:</span>
|
||||
<span style="color:Green;">//</span>
|
||||
<span style="color:Green;">// Major Version</span>
|
||||
<span style="color:Green;">// Minor Version </span>
|
||||
<span style="color:Green;">// Build Number</span>
|
||||
<span style="color:Green;">// Revision</span>
|
||||
<span style="color:Green;">//</span>
|
||||
<span style="color:Green;">// You can specify all the values or you can default the Revision and Build Numbers </span>
|
||||
<span style="color:Green;">// by using the '*' as shown below:</span>
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyVersion(<span style="color:#A31515;">"1.0.0.0"</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: AssemblyFileVersion(<span style="color:#A31515;">"1.0.0.0"</span>)]
|
||||
[<span style="color:Blue;">assembly</span>: NeutralResourcesLanguageAttribute(<span style="color:#A31515;">""</span>)]
|
||||
|
||||
</pre></div>
|
|
@ -1,37 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Resources;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Global")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Fnord")]
|
||||
[assembly: AssemblyProduct("Global")]
|
||||
[assembly: AssemblyCopyright("Copyright © Fnord 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f4fd840f-e0b8-431f-8e32-c58a82baaf36")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("")]
|
|
@ -1,36 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">// keywords_base.cs</span>
|
||||
<span style="color:Green;">// Accessing base class members</span>
|
||||
<span style="color:Blue;">using</span> System;
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> Person
|
||||
{
|
||||
<span style="color:Blue;">protected</span> <span style="color:Blue;">string</span> ssn = <span style="color:#A31515;">"444-55-6666"</span>;
|
||||
<span style="color:Blue;">protected</span> <span style="color:Blue;">string</span> name = <span style="color:#A31515;">"John L. Malgraine"</span>;
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">virtual</span> <span style="color:Blue;">void</span> GetInfo()
|
||||
{
|
||||
Console.WriteLine(<span style="color:#A31515;">"Name: {0}"</span>, name);
|
||||
Console.WriteLine(<span style="color:#A31515;">"SSN: {0}"</span>, ssn);
|
||||
}
|
||||
}
|
||||
<span style="color:Blue;">class</span> Employee : Person
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">string</span> id = <span style="color:#A31515;">"ABC567EFG"</span>;
|
||||
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">override</span> <span style="color:Blue;">void</span> GetInfo()
|
||||
{
|
||||
<span style="color:Green;">// Calling the base class GetInfo method:</span>
|
||||
<span style="color:Blue;">base</span>.GetInfo();
|
||||
Console.WriteLine(<span style="color:#A31515;">"Employee ID: {0}"</span>, id);
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:Blue;">class</span> TestClass
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">static</span> <span style="color:Blue;">void</span> Main()
|
||||
{
|
||||
Employee E = <span style="color:Blue;">new</span> Employee();
|
||||
E.GetInfo();
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,34 +0,0 @@
|
|||
// keywords_base.cs
|
||||
// Accessing base class members
|
||||
using System;
|
||||
public class Person
|
||||
{
|
||||
protected string ssn = "444-55-6666";
|
||||
protected string name = "John L. Malgraine";
|
||||
|
||||
public virtual void GetInfo()
|
||||
{
|
||||
Console.WriteLine("Name: {0}", name);
|
||||
Console.WriteLine("SSN: {0}", ssn);
|
||||
}
|
||||
}
|
||||
class Employee : Person
|
||||
{
|
||||
public string id = "ABC567EFG";
|
||||
|
||||
public override void GetInfo()
|
||||
{
|
||||
// Calling the base class GetInfo method:
|
||||
base.GetInfo();
|
||||
Console.WriteLine("Employee ID: {0}", id);
|
||||
}
|
||||
}
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Employee E = new Employee();
|
||||
E.GetInfo();
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">using</span> System;
|
||||
|
||||
<span style="color:Blue;">namespace</span> Xunit
|
||||
{
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"><summary></span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Represents a logger used by <see cref="TestRunner"/> and <see cref="XmlLoggerAdapter"/>.</span>
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"></summary></span>
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">interface</span> IRunnerLogger
|
||||
{
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Xunit
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a logger used by <see cref="TestRunner"/> and <see cref="XmlLoggerAdapter"/>.
|
||||
/// </summary>
|
||||
public interface IRunnerLogger
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> IntermediateProject :
|
||||
IIntermediateProject,
|
||||
IAttributeDeclarationTarget
|
||||
{
|
||||
<span style="color:Blue;">#region</span> IntermediateProject data members.
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"><summary></span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Data member for <see cref="Classes"/>.</span>
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"></summary></span>
|
||||
<span style="color:Blue;">private</span> IClassTypes classes;
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"><summary></span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Data member for <see cref="Delegates"/>.</span>
|
||||
<span style="color:Gray;">///</span> <span style="color:Gray;"></summary></span>
|
||||
<span style="color:Blue;">private</span> IDelegateTypes delegates;
|
||||
<span style="color:Blue;">#endregion</span>
|
||||
}
|
||||
</pre></div>
|
|
@ -1,15 +0,0 @@
|
|||
public class IntermediateProject :
|
||||
IIntermediateProject,
|
||||
IAttributeDeclarationTarget
|
||||
{
|
||||
#region IntermediateProject data members.
|
||||
/// <summary>
|
||||
/// Data member for <see cref="Classes"/>.
|
||||
/// </summary>
|
||||
private IClassTypes classes;
|
||||
/// <summary>
|
||||
/// Data member for <see cref="Delegates"/>.
|
||||
/// </summary>
|
||||
private IDelegateTypes delegates;
|
||||
#endregion
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">using</span> System.Linq;
|
||||
|
||||
<span style="color:Green;">// keywords_base.cs</span>
|
||||
<span style="color:Green;">// Accessing base class members</span>
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> LinqTest
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">void</span> DoSomething()
|
||||
{
|
||||
LinqObj[] data = <span style="color:Blue;">new</span>[]
|
||||
{
|
||||
<span style="color:Blue;">new</span> LinqObj { Key = <span style="color:#A31515;">"abc"</span>, Value = <span style="color:#A31515;">"def"</span> },
|
||||
<span style="color:Blue;">new</span> LinqObj { Key = <span style="color:#A31515;">"def"</span>, Value = <span style="color:#A31515;">"ghi"</span> }
|
||||
};
|
||||
|
||||
<span style="color:Blue;">var</span> test = <span style="color:Blue;">from</span> d <span style="color:Blue;">in</span> data
|
||||
<span style="color:Blue;">join</span> d2 <span style="color:Blue;">in</span> data <span style="color:Blue;">on</span> d.Key <span style="color:Blue;">equals</span> d2.Key
|
||||
<span style="color:Blue;">group</span> d <span style="color:Blue;">by</span> d.Key <span style="color:Blue;">into</span> g
|
||||
<span style="color:Blue;">orderby</span> g.Key <span style="color:Blue;">ascending</span>, g.Key <span style="color:Blue;">descending</span>
|
||||
<span style="color:Blue;">let</span> w = g.Key
|
||||
<span style="color:Blue;">where</span> g.Key == <span style="color:#A31515;">"abc"</span>
|
||||
<span style="color:Blue;">select</span> g;
|
||||
}
|
||||
|
||||
<span style="color:Blue;">private</span> <span style="color:Blue;">class</span> LinqObj
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">string</span> Key { <span style="color:Blue;">get</span>; <span style="color:Blue;">set</span>; }
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">string</span> Value { <span style="color:Blue;">get</span>; <span style="color:Blue;">set</span>; }
|
||||
}
|
||||
}
|
||||
|
||||
</pre></div>
|
|
@ -1,29 +0,0 @@
|
|||
using System.Linq;
|
||||
|
||||
// keywords_base.cs
|
||||
// Accessing base class members
|
||||
public class LinqTest
|
||||
{
|
||||
public void DoSomething()
|
||||
{
|
||||
LinqObj[] data = new[]
|
||||
{
|
||||
new LinqObj { Key = "abc", Value = "def" },
|
||||
new LinqObj { Key = "def", Value = "ghi" }
|
||||
};
|
||||
|
||||
var test = from d in data
|
||||
join d2 in data on d.Key equals d2.Key
|
||||
group d by d.Key into g
|
||||
orderby g.Key ascending, g.Key descending
|
||||
let w = g.Key
|
||||
where g.Key == "abc"
|
||||
select g;
|
||||
}
|
||||
|
||||
private class LinqObj
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> StringEncoding
|
||||
{
|
||||
<span style="color:Blue;">public</span> <span style="color:Blue;">void</span> Foo()
|
||||
{
|
||||
<span style="color:Blue;">string</span> a = <span style="color:#A31515;">@"""someText"""</span>;
|
||||
<span style="color:Blue;">string</span> b = <span style="color:#A31515;">"\"someText\""</span>;
|
||||
<span style="color:Blue;">string</span> c = <span style="color:#A31515;">@"
|
||||
""someText""
|
||||
"</span>;
|
||||
<span style="color:Blue;">char</span> d = <span style="color:#A31515;">'a'</span>;
|
||||
<span style="color:Blue;">char</span> e = <span style="color:#A31515;">'\''</span>;
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,13 +0,0 @@
|
|||
public class StringEncoding
|
||||
{
|
||||
public void Foo()
|
||||
{
|
||||
string a = @"""someText""";
|
||||
string b = "\"someText\"";
|
||||
string c = @"
|
||||
""someText""
|
||||
";
|
||||
char d = 'a';
|
||||
char e = '\'';
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,675 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">// This sample will guide you through elements of the F# language. </span>
|
||||
<span style="color:Green;">//</span>
|
||||
<span style="color:Green;">// *******************************************************************************************************</span>
|
||||
<span style="color:Green;">// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter or right-click </span>
|
||||
<span style="color:Green;">// and select "Execute in Interactive". You can open the F# Interactive Window from the "View" menu. </span>
|
||||
<span style="color:Green;">// *******************************************************************************************************</span>
|
||||
<span style="color:Green;">//</span>
|
||||
<span style="color:Green;">// For more about F#, see:</span>
|
||||
<span style="color:Green;">// http://fsharp.net</span>
|
||||
<span style="color:Green;">//</span>
|
||||
<span style="color:Green;">// For additional templates to use with F#, see the 'Online Templates' in Visual Studio, </span>
|
||||
<span style="color:Green;">// 'New Project' --> 'Online Templates'</span>
|
||||
<span style="color:Green;">//</span>
|
||||
<span style="color:Green;">// For specific F# topics, see:</span>
|
||||
<span style="color:Green;">// http://go.microsoft.com/fwlink/?LinkID=234174 (F# Development Portal)</span>
|
||||
<span style="color:Green;">// http://go.microsoft.com/fwlink/?LinkID=124614 (Code Gallery)</span>
|
||||
<span style="color:Green;">// http://go.microsoft.com/fwlink/?LinkId=235173 (Math/Stats Programming)</span>
|
||||
<span style="color:Green;">// http://go.microsoft.com/fwlink/?LinkId=235176 (Charting)</span>
|
||||
|
||||
<span style="color:Green;">// Contents:</span>
|
||||
<span style="color:Green;">// - Integers and basic functions</span>
|
||||
<span style="color:Green;">// - Booleans</span>
|
||||
<span style="color:Green;">// - Strings</span>
|
||||
<span style="color:Green;">// - Tuples</span>
|
||||
<span style="color:Green;">// - Lists and list processing</span>
|
||||
<span style="color:Green;">// - Classes</span>
|
||||
<span style="color:Green;">// - Generic classes</span>
|
||||
<span style="color:Green;">// - Implementing interfaces</span>
|
||||
<span style="color:Green;">// - Arrays</span>
|
||||
<span style="color:Green;">// - Sequences</span>
|
||||
<span style="color:Green;">// - Recursive functions</span>
|
||||
<span style="color:Green;">// - Record types</span>
|
||||
<span style="color:Green;">// - Union types</span>
|
||||
<span style="color:Green;">// - Option types </span>
|
||||
<span style="color:Green;">// - Pattern matching </span>
|
||||
<span style="color:Green;">// - Units of measure </span>
|
||||
<span style="color:Green;">// - Parallel array programming</span>
|
||||
<span style="color:Green;">// - Using events</span>
|
||||
<span style="color:Green;">// - Database access using type providers</span>
|
||||
<span style="color:Green;">// - OData access using type providers</span>
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Integers and basic functions</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> Integers =
|
||||
<span style="color:Blue;">let</span> sampleInteger = 176
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Do some arithmetic starting with the first integer</span>
|
||||
<span style="color:Blue;">let</span> sampleInteger2 = (sampleInteger/4 + 5 - 7) * 4
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A list of the numbers from 0 to 99</span>
|
||||
<span style="color:Blue;">let</span> sampleNumbers = [ 0 .. 99 ]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A list of all tuples containing all the numbers from 0 to 99 and their squares</span>
|
||||
<span style="color:Blue;">let</span> sampleTableOfSquares = [ <span style="color:Blue;">for</span> i <span style="color:Blue;">in</span> 0 .. 99 <span style="color:Blue;">-></span> (i, i*i) ]
|
||||
|
||||
<span style="color:Green;">// The next line prints a list that includes tuples, using %A for generic printing</span>
|
||||
printfn <span style="color:#A31515;">"The table of squares from 0 to 99 is:\n%A"</span> sampleTableOfSquares
|
||||
|
||||
|
||||
<span style="color:Blue;">module</span> BasicFunctions =
|
||||
|
||||
<span style="color:Green;">// Use 'let' to define a function that accepts an integer argument and returns an integer. </span>
|
||||
<span style="color:Blue;">let</span> func1 x = x*x + 3
|
||||
|
||||
<span style="color:Green;">// Parenthesis are optional for function arguments</span>
|
||||
<span style="color:Blue;">let</span> func1a (x) = x*x + 3
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Apply the function, naming the function return result using 'let'. </span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> The variable type is inferred from the function return type.</span>
|
||||
<span style="color:Blue;">let</span> result1 = func1 4573
|
||||
printfn <span style="color:#A31515;">"The result of squaring the integer 4573 and adding 3 is %d"</span> result1
|
||||
|
||||
<span style="color:Green;">// When needed, annotate the type of a parameter name using '(argument:type)'</span>
|
||||
<span style="color:Blue;">let</span> func2 (x:int) = 2*x*x - x/5 + 3
|
||||
|
||||
<span style="color:Blue;">let</span> result2 = func2 (7 + 4)
|
||||
printfn <span style="color:#A31515;">"The result of applying the 1st sample function to (7 + 4) is %d"</span> result2
|
||||
|
||||
<span style="color:Blue;">let</span> func3 x =
|
||||
<span style="color:Blue;">if</span> x < 100.0 <span style="color:Blue;">then</span>
|
||||
2.0*x*x - x/5.0 + 3.0
|
||||
<span style="color:Blue;">else</span>
|
||||
2.0*x*x + x/5.0 - 37.0
|
||||
|
||||
<span style="color:Blue;">let</span> result3 = func3 (6.5 + 4.5)
|
||||
printfn <span style="color:#A31515;">"The result of applying the 2nd sample function to (6.5 + 4.5) is %f"</span> result3
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Booleans</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> SomeBooleanValues =
|
||||
|
||||
<span style="color:Blue;">let</span> boolean1 = <span style="color:Blue;">true</span>
|
||||
<span style="color:Blue;">let</span> boolean2 = <span style="color:Blue;">false</span>
|
||||
|
||||
<span style="color:Blue;">let</span> boolean3 = not boolean1 && (boolean2 || <span style="color:Blue;">false</span>)
|
||||
|
||||
printfn <span style="color:#A31515;">"The expression 'not boolean1 && (boolean2 || false)' is %A"</span> boolean3
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Strings</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> StringManipulation =
|
||||
|
||||
<span style="color:Blue;">let</span> string1 = <span style="color:#A31515;">"Hello"</span>
|
||||
<span style="color:Blue;">let</span> string2 = <span style="color:#A31515;">"world"</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Use @ to create a verbatim string literal</span>
|
||||
<span style="color:Blue;">let</span> string3 = <span style="color:#A31515;">@"c:\Program Files\"</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Using a triple-quote string literal</span>
|
||||
<span style="color:Blue;">let</span> string4 = <span style="color:#A31515;">"""He said "hello world" after you did"""</span>
|
||||
|
||||
<span style="color:Blue;">let</span> helloWorld = string1 + <span style="color:#A31515;">" "</span> + string2 <span style="color:Green;">// concatenate the two strings with a space in between</span>
|
||||
printfn <span style="color:#A31515;">"%s"</span> helloWorld
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A string formed by taking the first 7 characters of one of the result strings</span>
|
||||
<span style="color:Blue;">let</span> substring = helloWorld.[0..6]
|
||||
printfn <span style="color:#A31515;">"%s"</span> substring
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Tuples (ordered sets of values)</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> Tuples =
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A simple tuple of integers</span>
|
||||
<span style="color:Blue;">let</span> tuple1 = (1, 2, 3)
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A function that swaps the order of two values in a tuple. </span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> QuickInfo shows that the function is inferred to have a generic type.</span>
|
||||
<span style="color:Blue;">let</span> swapElems (a, b) = (b, a)
|
||||
|
||||
printfn <span style="color:#A31515;">"The result of swapping (1, 2) is %A"</span> (swapElems (1,2))
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A tuple consisting of an integer, a string, and a double-precision floating point number</span>
|
||||
<span style="color:Blue;">let</span> tuple2 = (1, <span style="color:#A31515;">"fred"</span>, 3.1415)
|
||||
|
||||
printfn <span style="color:#A31515;">"tuple1: %A tuple2: %A"</span> tuple1 tuple2
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Lists and list processing</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> Lists =
|
||||
|
||||
<span style="color:Blue;">let</span> list1 = [ ] <span style="color:Gray;">///</span><span style="color:Green;"> an empty list</span>
|
||||
|
||||
<span style="color:Blue;">let</span> list2 = [ 1; 2; 3 ] <span style="color:Gray;">///</span><span style="color:Green;"> list of 3 elements</span>
|
||||
|
||||
<span style="color:Blue;">let</span> list3 = 42 :: list2 <span style="color:Gray;">///</span><span style="color:Green;"> a new list with '42' added to the beginning</span>
|
||||
|
||||
<span style="color:Blue;">let</span> numberList = [ 1 .. 1000 ] <span style="color:Gray;">///</span><span style="color:Green;"> list of integers from 1 to 1000</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A list containing all the days of the year</span>
|
||||
<span style="color:Blue;">let</span> daysList =
|
||||
[ <span style="color:Blue;">for</span> month <span style="color:Blue;">in</span> 1 .. 12 <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">for</span> day <span style="color:Blue;">in</span> 1 .. System.DateTime.DaysInMonth(2012, month) <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">yield</span> System.DateTime(2012, month, day) ]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A list containing the tuples which are the coordinates of the black squares on a chess board.</span>
|
||||
<span style="color:Blue;">let</span> blackSquares =
|
||||
[ <span style="color:Blue;">for</span> i <span style="color:Blue;">in</span> 0 .. 7 <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">for</span> j <span style="color:Blue;">in</span> 0 .. 7 <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">if</span> (i+j) % 2 = 1 <span style="color:Blue;">then</span>
|
||||
<span style="color:Blue;">yield</span> (i, j) ]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Square the numbers in numberList, using the pipeline operator to pass an argument to List.map </span>
|
||||
<span style="color:Blue;">let</span> squares =
|
||||
numberList
|
||||
|> List.map (<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> x*x)
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Computes the sum of the squares of the numbers divisible by 3.</span>
|
||||
<span style="color:Blue;">let</span> sumOfSquaresUpTo n =
|
||||
numberList
|
||||
|> List.filter (<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> x % 3 = 0)
|
||||
|> List.sumBy (<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> x * x)
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Classes</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> DefiningClasses =
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> The class's constructor takes two arguments: dx and dy, both of type 'float'. </span>
|
||||
<span style="color:Blue;">type</span> Vector2D(dx : float, dy : float) =
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> The length of the vector, computed when the object is constructed</span>
|
||||
<span style="color:Blue;">let</span> length = sqrt (dx*dx + dy*dy)
|
||||
|
||||
<span style="color:Green;">// 'this' specifies a name for the object's self identifier.</span>
|
||||
<span style="color:Green;">// In instance methods, it must appear before the member name.</span>
|
||||
<span style="color:Blue;">member</span> this.DX = dx
|
||||
|
||||
<span style="color:Blue;">member</span> this.DY = dy
|
||||
|
||||
<span style="color:Blue;">member</span> this.Length = length
|
||||
|
||||
<span style="color:Blue;">member</span> this.Scale(k) = Vector2D(k * this.DX, k * this.DY)
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> An instance of the Vector2D class</span>
|
||||
<span style="color:Blue;">let</span> vector1 = Vector2D(3.0, 4.0)
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Get a new scaled vector object, without modifying the original object </span>
|
||||
<span style="color:Blue;">let</span> vector2 = vector1.Scale(10.0)
|
||||
|
||||
printfn <span style="color:#A31515;">"Length of vector1: %f Length of vector2: %f"</span> vector1.Length vector2.Length
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Generic classes</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> DefiningGenericClasses =
|
||||
|
||||
<span style="color:Blue;">type</span> StateTracker<<span style="color:#A31515;">'T>(initialElement: '</span>T) = <span style="color:Green;">// 'T is the type parameter for the class</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Store the states in an array</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">mutable</span> states = [ initialElement ]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Add a new element to the list of states</span>
|
||||
<span style="color:Blue;">member</span> this.UpdateState newState =
|
||||
states <- newState :: states <span style="color:Green;">// use the '<-' operator to mutate the value</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Get the entire list of historical states</span>
|
||||
<span style="color:Blue;">member</span> this.History = states
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Get the latest state</span>
|
||||
<span style="color:Blue;">member</span> this.Current = states.Head
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> An 'int' instance of the state tracker class. Note that the type parameter is inferred.</span>
|
||||
<span style="color:Blue;">let</span> tracker = StateTracker 10
|
||||
|
||||
<span style="color:Green;">// Add a state</span>
|
||||
tracker.UpdateState 17
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Implementing interfaces</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Type that implements IDisposable</span>
|
||||
<span style="color:Blue;">type</span> ReadFile() =
|
||||
|
||||
<span style="color:Blue;">let</span> file = <span style="color:Blue;">new</span> System.IO.StreamReader(<span style="color:#A31515;">"readme.txt"</span>)
|
||||
|
||||
<span style="color:Blue;">member</span> this.ReadLine() = file.ReadLine()
|
||||
|
||||
<span style="color:Green;">// this class's implementation of IDisposable members</span>
|
||||
<span style="color:Blue;">interface</span> System.IDisposable <span style="color:Blue;">with</span>
|
||||
<span style="color:Blue;">member</span> this.Dispose() = file.Close()
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Arrays</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> Arrays =
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> The empty array</span>
|
||||
<span style="color:Blue;">let</span> array1 = [| |]
|
||||
|
||||
<span style="color:Blue;">let</span> array2 = [| <span style="color:#A31515;">"hello"</span>; <span style="color:#A31515;">"world"</span>; <span style="color:#A31515;">"and"</span>; <span style="color:#A31515;">"hello"</span>; <span style="color:#A31515;">"world"</span>; <span style="color:#A31515;">"again"</span> |]
|
||||
|
||||
<span style="color:Blue;">let</span> array3 = [| 1 .. 1000 |]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> An array containing only the words "hello" and "world"</span>
|
||||
<span style="color:Blue;">let</span> array4 = [| <span style="color:Blue;">for</span> word <span style="color:Blue;">in</span> array2 <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">if</span> word.Contains(<span style="color:#A31515;">"l"</span>) <span style="color:Blue;">then</span>
|
||||
<span style="color:Blue;">yield</span> word |]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> An array initialized by index and containing the even numbers from 0 to 2000</span>
|
||||
<span style="color:Blue;">let</span> evenNumbers = Array.init 1001 (<span style="color:Blue;">fun</span> n <span style="color:Blue;">-></span> n * 2)
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> sub-array extracted using slicing notation</span>
|
||||
<span style="color:Blue;">let</span> evenNumbersSlice = evenNumbers.[0..500]
|
||||
|
||||
<span style="color:Blue;">for</span> word <span style="color:Blue;">in</span> array4 <span style="color:Blue;">do</span>
|
||||
printfn <span style="color:#A31515;">"word: %s"</span> word
|
||||
|
||||
<span style="color:Green;">// modify an array element using the left arrow assignment operator</span>
|
||||
array2.[1] <- <span style="color:#A31515;">"WORLD!"</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Calculates the sum of the lengths of the words that start with 'h'</span>
|
||||
<span style="color:Blue;">let</span> sumOfLengthsOfWords =
|
||||
array2
|
||||
|> Array.filter (<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> x.StartsWith <span style="color:#A31515;">"h"</span>)
|
||||
|> Array.sumBy (<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> x.Length)
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Sequences</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> Sequences =
|
||||
<span style="color:Green;">// Sequences are evaluated on-demand and are re-evaluated each time they are iterated. </span>
|
||||
<span style="color:Green;">// An F# sequence is an instance of a System.Collections.Generic.IEnumerable<'T>,</span>
|
||||
<span style="color:Green;">// so Seq functions can be applied to Lists and Arrays as well.</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> The empty sequence</span>
|
||||
<span style="color:Blue;">let</span> seq1 = Seq.empty
|
||||
|
||||
<span style="color:Blue;">let</span> seq2 = seq { <span style="color:Blue;">yield</span> <span style="color:#A31515;">"hello"</span>; <span style="color:Blue;">yield</span> <span style="color:#A31515;">"world"</span>; <span style="color:Blue;">yield</span> <span style="color:#A31515;">"and"</span>; <span style="color:Blue;">yield</span> <span style="color:#A31515;">"hello"</span>; <span style="color:Blue;">yield</span> <span style="color:#A31515;">"world"</span>; <span style="color:Blue;">yield</span> <span style="color:#A31515;">"again"</span> }
|
||||
|
||||
<span style="color:Blue;">let</span> numbersSeq = seq { 1 .. 1000 }
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> another array containing only the words "hello" and "world"</span>
|
||||
<span style="color:Blue;">let</span> seq3 =
|
||||
seq { <span style="color:Blue;">for</span> word <span style="color:Blue;">in</span> seq2 <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">if</span> word.Contains(<span style="color:#A31515;">"l"</span>) <span style="color:Blue;">then</span>
|
||||
<span style="color:Blue;">yield</span> word }
|
||||
|
||||
<span style="color:Blue;">let</span> evenNumbers = Seq.init 1001 (<span style="color:Blue;">fun</span> n <span style="color:Blue;">-></span> n * 2)
|
||||
|
||||
<span style="color:Blue;">let</span> rnd = System.Random()
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> An infinite sequence which is a random walk</span>
|
||||
<span style="color:Green;">// Use yield! to return each element of a subsequence, similar to IEnumerable.SelectMany.</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> randomWalk x =
|
||||
seq { <span style="color:Blue;">yield</span> x
|
||||
<span style="color:Blue;">yield!</span> randomWalk (x + rnd.NextDouble() - 0.5) }
|
||||
|
||||
<span style="color:Blue;">let</span> first100ValuesOfRandomWalk =
|
||||
randomWalk 5.0
|
||||
|> Seq.truncate 100
|
||||
|> Seq.toList
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Recursive functions</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> RecursiveFunctions =
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Compute the factorial of an integer. Use 'let rec' to define a recursive function</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> factorial n =
|
||||
<span style="color:Blue;">if</span> n = 0 <span style="color:Blue;">then</span> 1 <span style="color:Blue;">else</span> n * factorial (n-1)
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Computes the greatest common factor of two integers. </span>
|
||||
<span style="color:Green;">// Since all of the recursive calls are tail calls, the compiler will turn the function into a loop,</span>
|
||||
<span style="color:Green;">// which improves performance and reduces memory consumption.</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> greatestCommonFactor a b =
|
||||
<span style="color:Blue;">if</span> a = 0 <span style="color:Blue;">then</span> b
|
||||
<span style="color:Blue;">elif</span> a < b <span style="color:Blue;">then</span> greatestCommonFactor a (b - a)
|
||||
<span style="color:Blue;">else</span> greatestCommonFactor (a - b) b
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Computes the sum of a list of integers using recursion.</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> sumList xs =
|
||||
<span style="color:Blue;">match</span> xs <span style="color:Blue;">with</span>
|
||||
| [] <span style="color:Blue;">-></span> 0
|
||||
| y::ys <span style="color:Blue;">-></span> y + sumList ys
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Make the function tail recursive, using a helper function with a result accumulator</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> <span style="color:Blue;">private</span> sumListTailRecHelper accumulator xs =
|
||||
<span style="color:Blue;">match</span> xs <span style="color:Blue;">with</span>
|
||||
| [] <span style="color:Blue;">-></span> accumulator
|
||||
| y::ys <span style="color:Blue;">-></span> sumListTailRecHelper (accumulator+y) ys
|
||||
|
||||
<span style="color:Blue;">let</span> sumListTailRecursive xs = sumListTailRecHelper 0 xs
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Record types</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> RecordTypes =
|
||||
|
||||
<span style="color:Green;">// define a record type</span>
|
||||
<span style="color:Blue;">type</span> ContactCard =
|
||||
{ Name : string;
|
||||
Phone : string;
|
||||
Verified : bool }
|
||||
|
||||
<span style="color:Blue;">let</span> contact1 = { Name = <span style="color:#A31515;">"Alf"</span> ; Phone = <span style="color:#A31515;">"(206) 555-0157"</span> ; Verified = <span style="color:Blue;">false</span> }
|
||||
|
||||
<span style="color:Green;">// create a new record that is a copy of contact1, </span>
|
||||
<span style="color:Green;">// but has different values for the 'Phone' and 'Verified' fields</span>
|
||||
<span style="color:Blue;">let</span> contact2 = { contact1 <span style="color:Blue;">with</span> Phone = <span style="color:#A31515;">"(206) 555-0112"</span>; Verified = <span style="color:Blue;">true</span> }
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Converts a 'ContactCard' object to a string</span>
|
||||
<span style="color:Blue;">let</span> showCard c =
|
||||
c.Name + <span style="color:#A31515;">" Phone: "</span> + c.Phone + (<span style="color:Blue;">if</span> not c.Verified <span style="color:Blue;">then</span> <span style="color:#A31515;">" (unverified)"</span> <span style="color:Blue;">else</span> <span style="color:#A31515;">""</span>)
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Union types</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> UnionTypes =
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Represents the suit of a playing card</span>
|
||||
<span style="color:Blue;">type</span> Suit =
|
||||
| Hearts
|
||||
| Clubs
|
||||
| Diamonds
|
||||
| Spades
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Represents the rank of a playing card</span>
|
||||
<span style="color:Blue;">type</span> Rank =
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Represents the rank of cards 2 .. 10</span>
|
||||
| Value <span style="color:Blue;">of</span> int
|
||||
| Ace
|
||||
| King
|
||||
| Queen
|
||||
| Jack
|
||||
<span style="color:Blue;">static</span> <span style="color:Blue;">member</span> GetAllRanks() =
|
||||
[ <span style="color:Blue;">yield</span> Ace
|
||||
<span style="color:Blue;">for</span> i <span style="color:Blue;">in</span> 2 .. 10 <span style="color:Blue;">do</span> <span style="color:Blue;">yield</span> Value i
|
||||
<span style="color:Blue;">yield</span> Jack
|
||||
<span style="color:Blue;">yield</span> Queen
|
||||
<span style="color:Blue;">yield</span> King ]
|
||||
|
||||
<span style="color:Blue;">type</span> Card = { Suit: Suit; Rank: Rank }
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Returns a list representing all the cards in the deck</span>
|
||||
<span style="color:Blue;">let</span> fullDeck =
|
||||
[ <span style="color:Blue;">for</span> suit <span style="color:Blue;">in</span> [ Hearts; Diamonds; Clubs; Spades] <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">for</span> rank <span style="color:Blue;">in</span> Rank.GetAllRanks() <span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">yield</span> { Suit=suit; Rank=rank } ]
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Converts a 'Card' object to a string</span>
|
||||
<span style="color:Blue;">let</span> showCard c =
|
||||
<span style="color:Blue;">let</span> rankString =
|
||||
<span style="color:Blue;">match</span> c.Rank <span style="color:Blue;">with</span>
|
||||
| Ace <span style="color:Blue;">-></span> <span style="color:#A31515;">"Ace"</span>
|
||||
| King <span style="color:Blue;">-></span> <span style="color:#A31515;">"King"</span>
|
||||
| Queen <span style="color:Blue;">-></span> <span style="color:#A31515;">"Queen"</span>
|
||||
| Jack <span style="color:Blue;">-></span> <span style="color:#A31515;">"Jack"</span>
|
||||
| Value n <span style="color:Blue;">-></span> string n
|
||||
<span style="color:Blue;">let</span> suitString =
|
||||
<span style="color:Blue;">match</span> c.Suit <span style="color:Blue;">with</span>
|
||||
| Clubs <span style="color:Blue;">-></span> <span style="color:#A31515;">"clubs"</span>
|
||||
| Diamonds <span style="color:Blue;">-></span> <span style="color:#A31515;">"diamonds"</span>
|
||||
| Spades <span style="color:Blue;">-></span> <span style="color:#A31515;">"spades"</span>
|
||||
| Hearts <span style="color:Blue;">-></span> <span style="color:#A31515;">"hearts"</span>
|
||||
rankString + <span style="color:#A31515;">" of "</span> + suitString
|
||||
|
||||
<span style="color:Blue;">let</span> printAllCards() =
|
||||
<span style="color:Blue;">for</span> card <span style="color:Blue;">in</span> fullDeck <span style="color:Blue;">do</span>
|
||||
printfn <span style="color:#A31515;">"%s"</span> (showCard card)
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Option types</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> OptionTypes =
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Option values are any kind of value tagged with either 'Some' or 'None'.</span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> They are used extensively in F# code to represent the cases where many other</span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> languages would use null references.</span>
|
||||
|
||||
<span style="color:Blue;">type</span> Customer = { zipCode : decimal option }
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Abstract class that computes the shipping zone for the customer's zip code, </span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> given implementations for the 'getState' and 'getShippingZone' abstract methods.</span>
|
||||
[<AbstractClass>]
|
||||
<span style="color:Blue;">type</span> ShippingCalculator =
|
||||
<span style="color:Blue;">abstract</span> getState : decimal <span style="color:Blue;">-></span> string option
|
||||
<span style="color:Blue;">abstract</span> getShippingZone : string <span style="color:Blue;">-></span> int
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Return the shipping zone corresponding to the customer's ZIP code</span>
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Customer may not yet have a ZIP code or the ZIP code may be invalid</span>
|
||||
<span style="color:Blue;">member</span> this.customerShippingZone(customer : Customer) =
|
||||
customer.zipCode |> Option.bind this.getState |> Option.map this.getShippingZone
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Pattern matching</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> PatternMatching =
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> A record for a person's first and last name</span>
|
||||
<span style="color:Blue;">type</span> Person = {
|
||||
First : string
|
||||
Last : string
|
||||
}
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> define a discriminated union of 3 different kinds of employees</span>
|
||||
<span style="color:Blue;">type</span> Employee =
|
||||
| Engineer <span style="color:Blue;">of</span> Person
|
||||
| Manager <span style="color:Blue;">of</span> Person * list<Employee> <span style="color:Green;">// manager has list of reports</span>
|
||||
| Executive <span style="color:Blue;">of</span> Person * list<Employee> * Employee <span style="color:Green;">// executive also has an assistant</span>
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> count everyone underneath the employee in the management hierarchy, including the employee</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> countReports(emp : Employee) =
|
||||
1 + <span style="color:Blue;">match</span> emp <span style="color:Blue;">with</span>
|
||||
| Engineer(id) <span style="color:Blue;">-></span>
|
||||
0
|
||||
| Manager(id, reports) <span style="color:Blue;">-></span>
|
||||
reports |> List.sumBy countReports
|
||||
| Executive(id, reports, assistant) <span style="color:Blue;">-></span>
|
||||
(reports |> List.sumBy countReports) + countReports assistant
|
||||
|
||||
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> find all managers/executives named "Dave" who do not have any reports</span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> findDaveWithOpenPosition(emps : Employee list) =
|
||||
emps
|
||||
|> List.filter(<span style="color:Blue;">function</span>
|
||||
| Manager({First = <span style="color:#A31515;">"Dave"</span>}, []) <span style="color:Blue;">-></span> <span style="color:Blue;">true</span> <span style="color:Green;">// [] matches the empty list</span>
|
||||
| Executive({First = <span style="color:#A31515;">"Dave"</span>}, [], _) <span style="color:Blue;">-></span> <span style="color:Blue;">true</span>
|
||||
| _ <span style="color:Blue;">-></span> <span style="color:Blue;">false</span>) <span style="color:Green;">// '_' is a wildcard pattern that matches anything</span>
|
||||
<span style="color:Green;">// this handles the "or else" case</span>
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Units of measure</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> UnitsOfMeasure =
|
||||
|
||||
<span style="color:Green;">// Code can be annotated with units of measure when using F# arithmetic over numeric types</span>
|
||||
|
||||
<span style="color:Blue;">open</span> Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
|
||||
|
||||
[<Measure>]
|
||||
<span style="color:Blue;">type</span> mile =
|
||||
<span style="color:Gray;">///</span><span style="color:Green;"> Conversion factor mile to meter: meter is defined in SI.UnitNames</span>
|
||||
<span style="color:Blue;">static</span> <span style="color:Blue;">member</span> asMeter = 1600.<meter/mile>
|
||||
|
||||
<span style="color:Blue;">let</span> d = 50.<mile> <span style="color:Green;">// Distance expressed using imperial units</span>
|
||||
<span style="color:Blue;">let</span> d' = d * mile.asMeter <span style="color:Green;">// Same distance expressed using metric system</span>
|
||||
|
||||
printfn <span style="color:#A31515;">"%A = %A"</span> d d'
|
||||
<span style="color:Green;">// let error = d + d' // Compile error: units of measure do not match</span>
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Parallel array programming</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> ParallelArrayProgramming =
|
||||
|
||||
<span style="color:Blue;">let</span> oneBigArray = [| 0 .. 100000 |]
|
||||
|
||||
<span style="color:Green;">// do some CPU intensive computation </span>
|
||||
<span style="color:Blue;">let</span> <span style="color:Blue;">rec</span> computeSomeFunction x =
|
||||
<span style="color:Blue;">if</span> x <= 2 <span style="color:Blue;">then</span> 1
|
||||
<span style="color:Blue;">else</span> computeSomeFunction (x - 1) + computeSomeFunction (x - 2)
|
||||
|
||||
<span style="color:Green;">// Do a parallel map over a large input array</span>
|
||||
<span style="color:Blue;">let</span> computeResults() = oneBigArray |> Array.Parallel.map (<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> computeSomeFunction (x % 20))
|
||||
|
||||
printfn <span style="color:#A31515;">"Parallel computation results: %A"</span> (computeResults())
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Using events</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> Events =
|
||||
|
||||
<span style="color:Blue;">open</span> System
|
||||
|
||||
<span style="color:Green;">// create instance of Event object that consists of subscription point (event.Publish) and event trigger (event.Trigger)</span>
|
||||
<span style="color:Blue;">let</span> simpleEvent = <span style="color:Blue;">new</span> Event<int>()
|
||||
|
||||
<span style="color:Green;">// add handler</span>
|
||||
simpleEvent.Publish.Add(
|
||||
<span style="color:Blue;">fun</span> x <span style="color:Blue;">-></span> printfn <span style="color:#A31515;">"this is handler was added with Publish.Add: %d"</span> x)
|
||||
|
||||
<span style="color:Green;">// trigger event</span>
|
||||
simpleEvent.Trigger(5)
|
||||
|
||||
<span style="color:Green;">// create instance of Event that follows standard .NET convention: (sender, EventArgs)</span>
|
||||
<span style="color:Blue;">let</span> eventForDelegateType = <span style="color:Blue;">new</span> Event<EventHandler, EventArgs>()
|
||||
|
||||
<span style="color:Green;">// add handler</span>
|
||||
eventForDelegateType.Publish.AddHandler(
|
||||
EventHandler(<span style="color:Blue;">fun</span> _ _ <span style="color:Blue;">-></span> printfn <span style="color:#A31515;">"this is handler was added with Publish.AddHandler"</span>))
|
||||
|
||||
<span style="color:Green;">// trigger event (note that sender argument should be set)</span>
|
||||
eventForDelegateType.Trigger(<span style="color:Blue;">null</span>, EventArgs.Empty)
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// Database access using type providers</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> DatabaseAccess =
|
||||
|
||||
<span style="color:Green;">// The easiest way to access a SQL database from F# is to use F# type providers. </span>
|
||||
<span style="color:Green;">// Add references to System.Data, System.Data.Linq, and FSharp.Data.TypeProviders.dll.</span>
|
||||
<span style="color:Green;">// You can use Server Explorer to build your ConnectionString. </span>
|
||||
|
||||
<span style="color:Green;">(*
|
||||
#r "System.Data"
|
||||
#r "System.Data.Linq"
|
||||
#r "FSharp.Data.TypeProviders"
|
||||
|
||||
open Microsoft.FSharp.Data.TypeProviders
|
||||
|
||||
type SqlConnection = SqlDataConnection<ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=tempdb;Integrated Security=True">
|
||||
let db = SqlConnection.GetDataContext()
|
||||
|
||||
let table =
|
||||
query { for r in db.Table do
|
||||
select r }
|
||||
*)</span>
|
||||
|
||||
|
||||
<span style="color:Green;">// You can also use SqlEntityConnection instead of SqlDataConnection, which accesses the database using Entity Framework.</span>
|
||||
|
||||
()
|
||||
|
||||
|
||||
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
<span style="color:Green;">// OData access using type providers</span>
|
||||
<span style="color:Green;">// ---------------------------------------------------------------</span>
|
||||
|
||||
<span style="color:Blue;">module</span> OData =
|
||||
|
||||
<span style="color:Green;">(*
|
||||
open System.Data.Services.Client
|
||||
open Microsoft.FSharp.Data.TypeProviders
|
||||
|
||||
// Consume demographics population and income OData service from Azure Marketplace.
|
||||
// For more information, see http://go.microsoft.com/fwlink/?LinkId=239712
|
||||
type Demographics = Microsoft.FSharp.Data.TypeProviders.ODataService<ServiceUri = "https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/">
|
||||
let ctx = Demographics.GetDataContext()
|
||||
|
||||
// Sign up for a Azure Marketplace account at https://datamarket.azure.com/account/info
|
||||
ctx.Credentials <- System.Net.NetworkCredential ("<your liveID>", "<your Azure Marketplace Key>")
|
||||
|
||||
let cities = query {
|
||||
for c in ctx.demog1 do
|
||||
where (c.StateName = "Washington")
|
||||
}
|
||||
|
||||
for c in cities do
|
||||
printfn "%A - %A" c.GeographyId c.PerCapitaIncome2010.Value
|
||||
*)</span>
|
||||
|
||||
()
|
||||
|
||||
|
||||
|
||||
<span style="color:Blue;">#if</span> COMPILED
|
||||
<span style="color:Blue;">module</span> BoilerPlateForForm =
|
||||
[<System.STAThread>]
|
||||
<span style="color:Blue;">do</span> ()
|
||||
<span style="color:Blue;">do</span> System.Windows.Forms.Application.Run()
|
||||
<span style="color:Blue;">#endif</span>
|
||||
|
||||
</pre></div>
|
|
@ -1,672 +0,0 @@
|
|||
// This sample will guide you through elements of the F# language.
|
||||
//
|
||||
// *******************************************************************************************************
|
||||
// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter or right-click
|
||||
// and select "Execute in Interactive". You can open the F# Interactive Window from the "View" menu.
|
||||
// *******************************************************************************************************
|
||||
//
|
||||
// For more about F#, see:
|
||||
// http://fsharp.net
|
||||
//
|
||||
// For additional templates to use with F#, see the 'Online Templates' in Visual Studio,
|
||||
// 'New Project' --> 'Online Templates'
|
||||
//
|
||||
// For specific F# topics, see:
|
||||
// http://go.microsoft.com/fwlink/?LinkID=234174 (F# Development Portal)
|
||||
// http://go.microsoft.com/fwlink/?LinkID=124614 (Code Gallery)
|
||||
// http://go.microsoft.com/fwlink/?LinkId=235173 (Math/Stats Programming)
|
||||
// http://go.microsoft.com/fwlink/?LinkId=235176 (Charting)
|
||||
|
||||
// Contents:
|
||||
// - Integers and basic functions
|
||||
// - Booleans
|
||||
// - Strings
|
||||
// - Tuples
|
||||
// - Lists and list processing
|
||||
// - Classes
|
||||
// - Generic classes
|
||||
// - Implementing interfaces
|
||||
// - Arrays
|
||||
// - Sequences
|
||||
// - Recursive functions
|
||||
// - Record types
|
||||
// - Union types
|
||||
// - Option types
|
||||
// - Pattern matching
|
||||
// - Units of measure
|
||||
// - Parallel array programming
|
||||
// - Using events
|
||||
// - Database access using type providers
|
||||
// - OData access using type providers
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Integers and basic functions
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module Integers =
|
||||
let sampleInteger = 176
|
||||
|
||||
/// Do some arithmetic starting with the first integer
|
||||
let sampleInteger2 = (sampleInteger/4 + 5 - 7) * 4
|
||||
|
||||
/// A list of the numbers from 0 to 99
|
||||
let sampleNumbers = [ 0 .. 99 ]
|
||||
|
||||
/// A list of all tuples containing all the numbers from 0 to 99 and their squares
|
||||
let sampleTableOfSquares = [ for i in 0 .. 99 -> (i, i*i) ]
|
||||
|
||||
// The next line prints a list that includes tuples, using %A for generic printing
|
||||
printfn "The table of squares from 0 to 99 is:\n%A" sampleTableOfSquares
|
||||
|
||||
|
||||
module BasicFunctions =
|
||||
|
||||
// Use 'let' to define a function that accepts an integer argument and returns an integer.
|
||||
let func1 x = x*x + 3
|
||||
|
||||
// Parenthesis are optional for function arguments
|
||||
let func1a (x) = x*x + 3
|
||||
|
||||
/// Apply the function, naming the function return result using 'let'.
|
||||
/// The variable type is inferred from the function return type.
|
||||
let result1 = func1 4573
|
||||
printfn "The result of squaring the integer 4573 and adding 3 is %d" result1
|
||||
|
||||
// When needed, annotate the type of a parameter name using '(argument:type)'
|
||||
let func2 (x:int) = 2*x*x - x/5 + 3
|
||||
|
||||
let result2 = func2 (7 + 4)
|
||||
printfn "The result of applying the 1st sample function to (7 + 4) is %d" result2
|
||||
|
||||
let func3 x =
|
||||
if x < 100.0 then
|
||||
2.0*x*x - x/5.0 + 3.0
|
||||
else
|
||||
2.0*x*x + x/5.0 - 37.0
|
||||
|
||||
let result3 = func3 (6.5 + 4.5)
|
||||
printfn "The result of applying the 2nd sample function to (6.5 + 4.5) is %f" result3
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Booleans
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module SomeBooleanValues =
|
||||
|
||||
let boolean1 = true
|
||||
let boolean2 = false
|
||||
|
||||
let boolean3 = not boolean1 && (boolean2 || false)
|
||||
|
||||
printfn "The expression 'not boolean1 && (boolean2 || false)' is %A" boolean3
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Strings
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module StringManipulation =
|
||||
|
||||
let string1 = "Hello"
|
||||
let string2 = "world"
|
||||
|
||||
/// Use @ to create a verbatim string literal
|
||||
let string3 = @"c:\Program Files\"
|
||||
|
||||
/// Using a triple-quote string literal
|
||||
let string4 = """He said "hello world" after you did"""
|
||||
|
||||
let helloWorld = string1 + " " + string2 // concatenate the two strings with a space in between
|
||||
printfn "%s" helloWorld
|
||||
|
||||
/// A string formed by taking the first 7 characters of one of the result strings
|
||||
let substring = helloWorld.[0..6]
|
||||
printfn "%s" substring
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Tuples (ordered sets of values)
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module Tuples =
|
||||
|
||||
/// A simple tuple of integers
|
||||
let tuple1 = (1, 2, 3)
|
||||
|
||||
/// A function that swaps the order of two values in a tuple.
|
||||
/// QuickInfo shows that the function is inferred to have a generic type.
|
||||
let swapElems (a, b) = (b, a)
|
||||
|
||||
printfn "The result of swapping (1, 2) is %A" (swapElems (1,2))
|
||||
|
||||
/// A tuple consisting of an integer, a string, and a double-precision floating point number
|
||||
let tuple2 = (1, "fred", 3.1415)
|
||||
|
||||
printfn "tuple1: %A tuple2: %A" tuple1 tuple2
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Lists and list processing
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module Lists =
|
||||
|
||||
let list1 = [ ] /// an empty list
|
||||
|
||||
let list2 = [ 1; 2; 3 ] /// list of 3 elements
|
||||
|
||||
let list3 = 42 :: list2 /// a new list with '42' added to the beginning
|
||||
|
||||
let numberList = [ 1 .. 1000 ] /// list of integers from 1 to 1000
|
||||
|
||||
/// A list containing all the days of the year
|
||||
let daysList =
|
||||
[ for month in 1 .. 12 do
|
||||
for day in 1 .. System.DateTime.DaysInMonth(2012, month) do
|
||||
yield System.DateTime(2012, month, day) ]
|
||||
|
||||
/// A list containing the tuples which are the coordinates of the black squares on a chess board.
|
||||
let blackSquares =
|
||||
[ for i in 0 .. 7 do
|
||||
for j in 0 .. 7 do
|
||||
if (i+j) % 2 = 1 then
|
||||
yield (i, j) ]
|
||||
|
||||
/// Square the numbers in numberList, using the pipeline operator to pass an argument to List.map
|
||||
let squares =
|
||||
numberList
|
||||
|> List.map (fun x -> x*x)
|
||||
|
||||
/// Computes the sum of the squares of the numbers divisible by 3.
|
||||
let sumOfSquaresUpTo n =
|
||||
numberList
|
||||
|> List.filter (fun x -> x % 3 = 0)
|
||||
|> List.sumBy (fun x -> x * x)
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Classes
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module DefiningClasses =
|
||||
|
||||
/// The class's constructor takes two arguments: dx and dy, both of type 'float'.
|
||||
type Vector2D(dx : float, dy : float) =
|
||||
/// The length of the vector, computed when the object is constructed
|
||||
let length = sqrt (dx*dx + dy*dy)
|
||||
|
||||
// 'this' specifies a name for the object's self identifier.
|
||||
// In instance methods, it must appear before the member name.
|
||||
member this.DX = dx
|
||||
|
||||
member this.DY = dy
|
||||
|
||||
member this.Length = length
|
||||
|
||||
member this.Scale(k) = Vector2D(k * this.DX, k * this.DY)
|
||||
|
||||
/// An instance of the Vector2D class
|
||||
let vector1 = Vector2D(3.0, 4.0)
|
||||
|
||||
/// Get a new scaled vector object, without modifying the original object
|
||||
let vector2 = vector1.Scale(10.0)
|
||||
|
||||
printfn "Length of vector1: %f Length of vector2: %f" vector1.Length vector2.Length
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Generic classes
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module DefiningGenericClasses =
|
||||
|
||||
type StateTracker<'T>(initialElement: 'T) = // 'T is the type parameter for the class
|
||||
|
||||
/// Store the states in an array
|
||||
let mutable states = [ initialElement ]
|
||||
|
||||
/// Add a new element to the list of states
|
||||
member this.UpdateState newState =
|
||||
states <- newState :: states // use the '<-' operator to mutate the value
|
||||
|
||||
/// Get the entire list of historical states
|
||||
member this.History = states
|
||||
|
||||
/// Get the latest state
|
||||
member this.Current = states.Head
|
||||
|
||||
/// An 'int' instance of the state tracker class. Note that the type parameter is inferred.
|
||||
let tracker = StateTracker 10
|
||||
|
||||
// Add a state
|
||||
tracker.UpdateState 17
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Implementing interfaces
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
/// Type that implements IDisposable
|
||||
type ReadFile() =
|
||||
|
||||
let file = new System.IO.StreamReader("readme.txt")
|
||||
|
||||
member this.ReadLine() = file.ReadLine()
|
||||
|
||||
// this class's implementation of IDisposable members
|
||||
interface System.IDisposable with
|
||||
member this.Dispose() = file.Close()
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Arrays
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module Arrays =
|
||||
|
||||
/// The empty array
|
||||
let array1 = [| |]
|
||||
|
||||
let array2 = [| "hello"; "world"; "and"; "hello"; "world"; "again" |]
|
||||
|
||||
let array3 = [| 1 .. 1000 |]
|
||||
|
||||
/// An array containing only the words "hello" and "world"
|
||||
let array4 = [| for word in array2 do
|
||||
if word.Contains("l") then
|
||||
yield word |]
|
||||
|
||||
/// An array initialized by index and containing the even numbers from 0 to 2000
|
||||
let evenNumbers = Array.init 1001 (fun n -> n * 2)
|
||||
|
||||
/// sub-array extracted using slicing notation
|
||||
let evenNumbersSlice = evenNumbers.[0..500]
|
||||
|
||||
for word in array4 do
|
||||
printfn "word: %s" word
|
||||
|
||||
// modify an array element using the left arrow assignment operator
|
||||
array2.[1] <- "WORLD!"
|
||||
|
||||
/// Calculates the sum of the lengths of the words that start with 'h'
|
||||
let sumOfLengthsOfWords =
|
||||
array2
|
||||
|> Array.filter (fun x -> x.StartsWith "h")
|
||||
|> Array.sumBy (fun x -> x.Length)
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Sequences
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module Sequences =
|
||||
// Sequences are evaluated on-demand and are re-evaluated each time they are iterated.
|
||||
// An F# sequence is an instance of a System.Collections.Generic.IEnumerable<'T>,
|
||||
// so Seq functions can be applied to Lists and Arrays as well.
|
||||
|
||||
/// The empty sequence
|
||||
let seq1 = Seq.empty
|
||||
|
||||
let seq2 = seq { yield "hello"; yield "world"; yield "and"; yield "hello"; yield "world"; yield "again" }
|
||||
|
||||
let numbersSeq = seq { 1 .. 1000 }
|
||||
|
||||
/// another array containing only the words "hello" and "world"
|
||||
let seq3 =
|
||||
seq { for word in seq2 do
|
||||
if word.Contains("l") then
|
||||
yield word }
|
||||
|
||||
let evenNumbers = Seq.init 1001 (fun n -> n * 2)
|
||||
|
||||
let rnd = System.Random()
|
||||
|
||||
/// An infinite sequence which is a random walk
|
||||
// Use yield! to return each element of a subsequence, similar to IEnumerable.SelectMany.
|
||||
let rec randomWalk x =
|
||||
seq { yield x
|
||||
yield! randomWalk (x + rnd.NextDouble() - 0.5) }
|
||||
|
||||
let first100ValuesOfRandomWalk =
|
||||
randomWalk 5.0
|
||||
|> Seq.truncate 100
|
||||
|> Seq.toList
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Recursive functions
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module RecursiveFunctions =
|
||||
|
||||
/// Compute the factorial of an integer. Use 'let rec' to define a recursive function
|
||||
let rec factorial n =
|
||||
if n = 0 then 1 else n * factorial (n-1)
|
||||
|
||||
/// Computes the greatest common factor of two integers.
|
||||
// Since all of the recursive calls are tail calls, the compiler will turn the function into a loop,
|
||||
// which improves performance and reduces memory consumption.
|
||||
let rec greatestCommonFactor a b =
|
||||
if a = 0 then b
|
||||
elif a < b then greatestCommonFactor a (b - a)
|
||||
else greatestCommonFactor (a - b) b
|
||||
|
||||
/// Computes the sum of a list of integers using recursion.
|
||||
let rec sumList xs =
|
||||
match xs with
|
||||
| [] -> 0
|
||||
| y::ys -> y + sumList ys
|
||||
|
||||
/// Make the function tail recursive, using a helper function with a result accumulator
|
||||
let rec private sumListTailRecHelper accumulator xs =
|
||||
match xs with
|
||||
| [] -> accumulator
|
||||
| y::ys -> sumListTailRecHelper (accumulator+y) ys
|
||||
|
||||
let sumListTailRecursive xs = sumListTailRecHelper 0 xs
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Record types
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module RecordTypes =
|
||||
|
||||
// define a record type
|
||||
type ContactCard =
|
||||
{ Name : string;
|
||||
Phone : string;
|
||||
Verified : bool }
|
||||
|
||||
let contact1 = { Name = "Alf" ; Phone = "(206) 555-0157" ; Verified = false }
|
||||
|
||||
// create a new record that is a copy of contact1,
|
||||
// but has different values for the 'Phone' and 'Verified' fields
|
||||
let contact2 = { contact1 with Phone = "(206) 555-0112"; Verified = true }
|
||||
|
||||
/// Converts a 'ContactCard' object to a string
|
||||
let showCard c =
|
||||
c.Name + " Phone: " + c.Phone + (if not c.Verified then " (unverified)" else "")
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Union types
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module UnionTypes =
|
||||
|
||||
/// Represents the suit of a playing card
|
||||
type Suit =
|
||||
| Hearts
|
||||
| Clubs
|
||||
| Diamonds
|
||||
| Spades
|
||||
|
||||
/// Represents the rank of a playing card
|
||||
type Rank =
|
||||
/// Represents the rank of cards 2 .. 10
|
||||
| Value of int
|
||||
| Ace
|
||||
| King
|
||||
| Queen
|
||||
| Jack
|
||||
static member GetAllRanks() =
|
||||
[ yield Ace
|
||||
for i in 2 .. 10 do yield Value i
|
||||
yield Jack
|
||||
yield Queen
|
||||
yield King ]
|
||||
|
||||
type Card = { Suit: Suit; Rank: Rank }
|
||||
|
||||
/// Returns a list representing all the cards in the deck
|
||||
let fullDeck =
|
||||
[ for suit in [ Hearts; Diamonds; Clubs; Spades] do
|
||||
for rank in Rank.GetAllRanks() do
|
||||
yield { Suit=suit; Rank=rank } ]
|
||||
|
||||
/// Converts a 'Card' object to a string
|
||||
let showCard c =
|
||||
let rankString =
|
||||
match c.Rank with
|
||||
| Ace -> "Ace"
|
||||
| King -> "King"
|
||||
| Queen -> "Queen"
|
||||
| Jack -> "Jack"
|
||||
| Value n -> string n
|
||||
let suitString =
|
||||
match c.Suit with
|
||||
| Clubs -> "clubs"
|
||||
| Diamonds -> "diamonds"
|
||||
| Spades -> "spades"
|
||||
| Hearts -> "hearts"
|
||||
rankString + " of " + suitString
|
||||
|
||||
let printAllCards() =
|
||||
for card in fullDeck do
|
||||
printfn "%s" (showCard card)
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Option types
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module OptionTypes =
|
||||
/// Option values are any kind of value tagged with either 'Some' or 'None'.
|
||||
/// They are used extensively in F# code to represent the cases where many other
|
||||
/// languages would use null references.
|
||||
|
||||
type Customer = { zipCode : decimal option }
|
||||
|
||||
/// Abstract class that computes the shipping zone for the customer's zip code,
|
||||
/// given implementations for the 'getState' and 'getShippingZone' abstract methods.
|
||||
[<AbstractClass>]
|
||||
type ShippingCalculator =
|
||||
abstract getState : decimal -> string option
|
||||
abstract getShippingZone : string -> int
|
||||
|
||||
/// Return the shipping zone corresponding to the customer's ZIP code
|
||||
/// Customer may not yet have a ZIP code or the ZIP code may be invalid
|
||||
member this.customerShippingZone(customer : Customer) =
|
||||
customer.zipCode |> Option.bind this.getState |> Option.map this.getShippingZone
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Pattern matching
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module PatternMatching =
|
||||
|
||||
/// A record for a person's first and last name
|
||||
type Person = {
|
||||
First : string
|
||||
Last : string
|
||||
}
|
||||
|
||||
/// define a discriminated union of 3 different kinds of employees
|
||||
type Employee =
|
||||
| Engineer of Person
|
||||
| Manager of Person * list<Employee> // manager has list of reports
|
||||
| Executive of Person * list<Employee> * Employee // executive also has an assistant
|
||||
|
||||
/// count everyone underneath the employee in the management hierarchy, including the employee
|
||||
let rec countReports(emp : Employee) =
|
||||
1 + match emp with
|
||||
| Engineer(id) ->
|
||||
0
|
||||
| Manager(id, reports) ->
|
||||
reports |> List.sumBy countReports
|
||||
| Executive(id, reports, assistant) ->
|
||||
(reports |> List.sumBy countReports) + countReports assistant
|
||||
|
||||
|
||||
/// find all managers/executives named "Dave" who do not have any reports
|
||||
let rec findDaveWithOpenPosition(emps : Employee list) =
|
||||
emps
|
||||
|> List.filter(function
|
||||
| Manager({First = "Dave"}, []) -> true // [] matches the empty list
|
||||
| Executive({First = "Dave"}, [], _) -> true
|
||||
| _ -> false) // '_' is a wildcard pattern that matches anything
|
||||
// this handles the "or else" case
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Units of measure
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module UnitsOfMeasure =
|
||||
|
||||
// Code can be annotated with units of measure when using F# arithmetic over numeric types
|
||||
|
||||
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
|
||||
|
||||
[<Measure>]
|
||||
type mile =
|
||||
/// Conversion factor mile to meter: meter is defined in SI.UnitNames
|
||||
static member asMeter = 1600.<meter/mile>
|
||||
|
||||
let d = 50.<mile> // Distance expressed using imperial units
|
||||
let d' = d * mile.asMeter // Same distance expressed using metric system
|
||||
|
||||
printfn "%A = %A" d d'
|
||||
// let error = d + d' // Compile error: units of measure do not match
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Parallel array programming
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module ParallelArrayProgramming =
|
||||
|
||||
let oneBigArray = [| 0 .. 100000 |]
|
||||
|
||||
// do some CPU intensive computation
|
||||
let rec computeSomeFunction x =
|
||||
if x <= 2 then 1
|
||||
else computeSomeFunction (x - 1) + computeSomeFunction (x - 2)
|
||||
|
||||
// Do a parallel map over a large input array
|
||||
let computeResults() = oneBigArray |> Array.Parallel.map (fun x -> computeSomeFunction (x % 20))
|
||||
|
||||
printfn "Parallel computation results: %A" (computeResults())
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Using events
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module Events =
|
||||
|
||||
open System
|
||||
|
||||
// create instance of Event object that consists of subscription point (event.Publish) and event trigger (event.Trigger)
|
||||
let simpleEvent = new Event<int>()
|
||||
|
||||
// add handler
|
||||
simpleEvent.Publish.Add(
|
||||
fun x -> printfn "this is handler was added with Publish.Add: %d" x)
|
||||
|
||||
// trigger event
|
||||
simpleEvent.Trigger(5)
|
||||
|
||||
// create instance of Event that follows standard .NET convention: (sender, EventArgs)
|
||||
let eventForDelegateType = new Event<EventHandler, EventArgs>()
|
||||
|
||||
// add handler
|
||||
eventForDelegateType.Publish.AddHandler(
|
||||
EventHandler(fun _ _ -> printfn "this is handler was added with Publish.AddHandler"))
|
||||
|
||||
// trigger event (note that sender argument should be set)
|
||||
eventForDelegateType.Trigger(null, EventArgs.Empty)
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Database access using type providers
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module DatabaseAccess =
|
||||
|
||||
// The easiest way to access a SQL database from F# is to use F# type providers.
|
||||
// Add references to System.Data, System.Data.Linq, and FSharp.Data.TypeProviders.dll.
|
||||
// You can use Server Explorer to build your ConnectionString.
|
||||
|
||||
(*
|
||||
#r "System.Data"
|
||||
#r "System.Data.Linq"
|
||||
#r "FSharp.Data.TypeProviders"
|
||||
|
||||
open Microsoft.FSharp.Data.TypeProviders
|
||||
|
||||
type SqlConnection = SqlDataConnection<ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=tempdb;Integrated Security=True">
|
||||
let db = SqlConnection.GetDataContext()
|
||||
|
||||
let table =
|
||||
query { for r in db.Table do
|
||||
select r }
|
||||
*)
|
||||
|
||||
|
||||
// You can also use SqlEntityConnection instead of SqlDataConnection, which accesses the database using Entity Framework.
|
||||
|
||||
()
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// OData access using type providers
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
module OData =
|
||||
|
||||
(*
|
||||
open System.Data.Services.Client
|
||||
open Microsoft.FSharp.Data.TypeProviders
|
||||
|
||||
// Consume demographics population and income OData service from Azure Marketplace.
|
||||
// For more information, see http://go.microsoft.com/fwlink/?LinkId=239712
|
||||
type Demographics = Microsoft.FSharp.Data.TypeProviders.ODataService<ServiceUri = "https://api.datamarket.azure.com/Esri/KeyUSDemographicsTrial/">
|
||||
let ctx = Demographics.GetDataContext()
|
||||
|
||||
// Sign up for a Azure Marketplace account at https://datamarket.azure.com/account/info
|
||||
ctx.Credentials <- System.Net.NetworkCredential ("<your liveID>", "<your Azure Marketplace Key>")
|
||||
|
||||
let cities = query {
|
||||
for c in ctx.demog1 do
|
||||
where (c.StateName = "Washington")
|
||||
}
|
||||
|
||||
for c in cities do
|
||||
printfn "%A - %A" c.GeographyId c.PerCapitaIncome2010.Value
|
||||
*)
|
||||
|
||||
()
|
||||
|
||||
|
||||
|
||||
#if COMPILED
|
||||
module BoilerPlateForForm =
|
||||
[<System.STAThread>]
|
||||
do ()
|
||||
do System.Windows.Forms.Application.Run()
|
||||
#endif
|
|
@ -1,134 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">/*
|
||||
more
|
||||
than
|
||||
one
|
||||
line
|
||||
comment
|
||||
*/</span>
|
||||
|
||||
<span style="color:Green;">// single line comment</span>
|
||||
|
||||
<span style="color:Green;"># a different single line comment</span>
|
||||
|
||||
$foo = <span style="color:#A31515;">'a string'</span>
|
||||
|
||||
$foo2 = <span style="color:#A31515;">"a string"</span>
|
||||
|
||||
<span style="color:Green;">//$foo = 'a string'</span>
|
||||
|
||||
<span style="color:Green;">//$foo2 = "a string"</span>
|
||||
|
||||
$foo3 = <span style="color:#A31515;">"a string"</span> <span style="color:Green;">// a comment</span>
|
||||
|
||||
<span style="color:Green;">/* Incorrect Method: */</span>
|
||||
<span style="color:Blue;">if</span>($a > $b):
|
||||
<span style="color:Blue;">echo</span> $a.<span style="color:#A31515;">" is greater than "</span>.$b;
|
||||
<span style="color:Blue;">else</span> <span style="color:Blue;">if</span>($a == $b): <span style="color:Green;">// Will not compile.</span>
|
||||
<span style="color:Blue;">echo</span> <span style="color:#A31515;">"The above line causes a parse error."</span>;
|
||||
<span style="color:Blue;">endif</span>;
|
||||
|
||||
<span style="color:Green;">/* Correct Method: */</span>
|
||||
<span style="color:Blue;">if</span>($a > $b):
|
||||
<span style="color:Blue;">echo</span> $a.<span style="color:#A31515;">" is greater than "</span>.$b;
|
||||
<span style="color:Blue;">elseif</span>($a == $b): <span style="color:Green;">// Note the combination of the words.</span>
|
||||
<span style="color:Blue;">echo</span> $a.<span style="color:#A31515;">" equals "</span>.$b;
|
||||
<span style="color:Blue;">else</span>:
|
||||
<span style="color:Blue;">echo</span> $a.<span style="color:#A31515;">" is neither greater than or equal to "</span>.$b;
|
||||
<span style="color:Blue;">endif</span>;
|
||||
|
||||
<?php
|
||||
$<span style="color:Blue;">file</span> = fopen(<span style="color:#A31515;">"welcome.txt"</span>, <span style="color:#A31515;">"r"</span>) <span style="color:Blue;">or</span> <span style="color:Blue;">exit</span>(<span style="color:#A31515;">"Unable to open file!"</span>);
|
||||
<span style="color:Green;">//Output a line of the file until the end is reached</span>
|
||||
|
||||
<span style="color:Green;">/* single line comment */</span>
|
||||
|
||||
<span style="color:Blue;">echo</span> <span style="color:#A31515;">"<table width=\"175\" border=\"1\" class=\"Table1\">\n"</span>;
|
||||
$regex = <span style="color:#A31515;">'/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/'</span>;
|
||||
|
||||
<span style="color:Blue;">while</span>(!feof($<span style="color:Blue;">file</span>))
|
||||
{
|
||||
<span style="color:Blue;">echo</span> fgets($<span style="color:Blue;">file</span>). <span style="color:#A31515;">"<br />"</span>;
|
||||
<span style="color:Green;">/* single line comment */</span>
|
||||
}
|
||||
<span style="color:Green;">/*multi line style
|
||||
* Second line
|
||||
* third line
|
||||
* fourth line
|
||||
*/</span>
|
||||
<span style="color:Blue;">fclose</span>($<span style="color:Blue;">file</span>);
|
||||
<span style="color:Blue;">mysqli_fetch_object</span>())
|
||||
<span style="color:Blue;">and</span>
|
||||
<span style="color:Blue;">__LINE__</span>
|
||||
<span style="color:Blue;">class</span>
|
||||
<span style="color:Blue;">die</span>()
|
||||
<span style="color:Blue;">empty</span>()
|
||||
<span style="color:Blue;">endswitch</span>
|
||||
<span style="color:Blue;">for</span>
|
||||
<span style="color:Blue;">include</span>()
|
||||
<span style="color:Blue;">print</span>()
|
||||
<span style="color:Blue;">switch</span>
|
||||
<span style="color:Blue;">__FUNCTION__</span>
|
||||
<span style="color:Blue;">interface</span>
|
||||
<span style="color:Blue;">protected</span>
|
||||
<span style="color:Blue;">throw</span>
|
||||
<span style="color:Blue;">or</span>
|
||||
<span style="color:Blue;">array</span>()
|
||||
<span style="color:Blue;">const</span>
|
||||
<span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">enddeclare</span>
|
||||
<span style="color:Blue;">endwhile</span>
|
||||
<span style="color:Blue;">foreach</span>
|
||||
<span style="color:Blue;">include_once</span>()
|
||||
<span style="color:Blue;">require</span>()
|
||||
<span style="color:Blue;">unset</span>()
|
||||
<span style="color:Blue;">__CLASS__</span>
|
||||
<span style="color:Blue;">implements</span>
|
||||
<span style="color:Blue;">abstract</span>
|
||||
<span style="color:Blue;">cfunction</span>
|
||||
<span style="color:Blue;">namespace</span>
|
||||
<span style="color:Blue;">xor</span>
|
||||
<span style="color:Blue;">as</span>
|
||||
<span style="color:Blue;">continue</span>
|
||||
<span style="color:Blue;">echo</span>()
|
||||
<span style="color:Blue;">endfor</span>
|
||||
<span style="color:Blue;">eval</span>()
|
||||
<span style="color:Blue;">function</span>
|
||||
<span style="color:Blue;">isset</span>()
|
||||
<span style="color:Blue;">require_once</span>()
|
||||
<span style="color:Blue;">use</span>
|
||||
<span style="color:Blue;">__METHOD__</span>
|
||||
<span style="color:Blue;">clone</span>
|
||||
<span style="color:Blue;">old_function</span>
|
||||
<span style="color:Blue;">goto</span>
|
||||
<span style="color:Blue;">__FILE__</span>
|
||||
<span style="color:Blue;">break</span>
|
||||
<span style="color:Blue;">declare</span>
|
||||
<span style="color:Blue;">else</span>
|
||||
<span style="color:Blue;">endforeach</span>
|
||||
<span style="color:Blue;">exit</span>()
|
||||
<span style="color:Blue;">global</span>
|
||||
<span style="color:Blue;">list</span>()
|
||||
<span style="color:Blue;">return</span>()
|
||||
<span style="color:Blue;">var</span>
|
||||
<span style="color:Blue;">final</span>
|
||||
<span style="color:Blue;">public</span>
|
||||
<span style="color:Blue;">try</span>
|
||||
this
|
||||
<span style="color:Blue;">exception</span>
|
||||
<span style="color:Blue;">case</span>
|
||||
<span style="color:Blue;">default</span>
|
||||
<span style="color:Blue;">elseif</span>
|
||||
<span style="color:Blue;">endif</span>
|
||||
<span style="color:Blue;">extends</span>
|
||||
<span style="color:Blue;">if</span>
|
||||
<span style="color:Blue;">new</span>
|
||||
<span style="color:Blue;">static</span>
|
||||
<span style="color:Blue;">while</span>
|
||||
<span style="color:Blue;">php_user_filter</span>
|
||||
<span style="color:Blue;">private</span>
|
||||
<span style="color:Blue;">catch</span>
|
||||
<span style="color:Blue;">final</span>
|
||||
?>
|
||||
|
||||
</pre></div>
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
more
|
||||
than
|
||||
one
|
||||
line
|
||||
comment
|
||||
*/
|
||||
|
||||
// single line comment
|
||||
|
||||
# a different single line comment
|
||||
|
||||
$foo = 'a string'
|
||||
|
||||
$foo2 = "a string"
|
||||
|
||||
//$foo = 'a string'
|
||||
|
||||
//$foo2 = "a string"
|
||||
|
||||
$foo3 = "a string" // a comment
|
||||
|
||||
/* Incorrect Method: */
|
||||
if($a > $b):
|
||||
echo $a." is greater than ".$b;
|
||||
else if($a == $b): // Will not compile.
|
||||
echo "The above line causes a parse error.";
|
||||
endif;
|
||||
|
||||
/* Correct Method: */
|
||||
if($a > $b):
|
||||
echo $a." is greater than ".$b;
|
||||
elseif($a == $b): // Note the combination of the words.
|
||||
echo $a." equals ".$b;
|
||||
else:
|
||||
echo $a." is neither greater than or equal to ".$b;
|
||||
endif;
|
||||
|
||||
<?php
|
||||
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
|
||||
//Output a line of the file until the end is reached
|
||||
|
||||
/* single line comment */
|
||||
|
||||
echo "<table width=\"175\" border=\"1\" class=\"Table1\">\n";
|
||||
$regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/';
|
||||
|
||||
while(!feof($file))
|
||||
{
|
||||
echo fgets($file). "<br />";
|
||||
/* single line comment */
|
||||
}
|
||||
/*multi line style
|
||||
* Second line
|
||||
* third line
|
||||
* fourth line
|
||||
*/
|
||||
fclose($file);
|
||||
mysqli_fetch_object())
|
||||
and
|
||||
__LINE__
|
||||
class
|
||||
die()
|
||||
empty()
|
||||
endswitch
|
||||
for
|
||||
include()
|
||||
print()
|
||||
switch
|
||||
__FUNCTION__
|
||||
interface
|
||||
protected
|
||||
throw
|
||||
or
|
||||
array()
|
||||
const
|
||||
do
|
||||
enddeclare
|
||||
endwhile
|
||||
foreach
|
||||
include_once()
|
||||
require()
|
||||
unset()
|
||||
__CLASS__
|
||||
implements
|
||||
abstract
|
||||
cfunction
|
||||
namespace
|
||||
xor
|
||||
as
|
||||
continue
|
||||
echo()
|
||||
endfor
|
||||
eval()
|
||||
function
|
||||
isset()
|
||||
require_once()
|
||||
use
|
||||
__METHOD__
|
||||
clone
|
||||
old_function
|
||||
goto
|
||||
__FILE__
|
||||
break
|
||||
declare
|
||||
else
|
||||
endforeach
|
||||
exit()
|
||||
global
|
||||
list()
|
||||
return()
|
||||
var
|
||||
final
|
||||
public
|
||||
try
|
||||
this
|
||||
exception
|
||||
case
|
||||
default
|
||||
elseif
|
||||
endif
|
||||
extends
|
||||
if
|
||||
new
|
||||
static
|
||||
while
|
||||
php_user_filter
|
||||
private
|
||||
catch
|
||||
final
|
||||
?>
|
|
@ -1,30 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">begin</span>
|
||||
<span style="color:Blue;">break</span>
|
||||
<span style="color:Blue;">catch</span>
|
||||
<span style="color:Blue;">continue</span>
|
||||
<span style="color:Blue;">data</span>
|
||||
<span style="color:Blue;">do</span>
|
||||
<span style="color:Blue;">dynamicparam</span>
|
||||
<span style="color:Blue;">elseif</span>
|
||||
<span style="color:Blue;">else</span>
|
||||
<span style="color:Blue;">end</span>
|
||||
<span style="color:Blue;">exit</span>
|
||||
<span style="color:Blue;">filter</span>
|
||||
<span style="color:Blue;">finally</span>
|
||||
<span style="color:Blue;">foreach</span>
|
||||
<span style="color:Blue;">for</span>
|
||||
<span style="color:Blue;">from</span>
|
||||
<span style="color:Blue;">function</span>
|
||||
<span style="color:Blue;">if</span>
|
||||
<span style="color:Blue;">in</span>
|
||||
<span style="color:Blue;">param</span>
|
||||
<span style="color:Blue;">process</span>
|
||||
<span style="color:Blue;">return</span>
|
||||
<span style="color:Blue;">switch</span>
|
||||
<span style="color:Blue;">throw</span>
|
||||
<span style="color:Blue;">trap</span>
|
||||
<span style="color:Blue;">try</span>
|
||||
<span style="color:Blue;">until</span>
|
||||
<span style="color:Blue;">while</span>
|
||||
</pre></div>
|
|
@ -1,28 +0,0 @@
|
|||
begin
|
||||
break
|
||||
catch
|
||||
continue
|
||||
data
|
||||
do
|
||||
dynamicparam
|
||||
elseif
|
||||
else
|
||||
end
|
||||
exit
|
||||
filter
|
||||
finally
|
||||
foreach
|
||||
for
|
||||
from
|
||||
function
|
||||
if
|
||||
in
|
||||
param
|
||||
process
|
||||
return
|
||||
switch
|
||||
throw
|
||||
trap
|
||||
try
|
||||
until
|
||||
while
|
|
@ -1,49 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">#-- Public Module Functions</span>
|
||||
<span style="color:Blue;">function</span> Exec
|
||||
{
|
||||
<span style="color:Green;"><#
|
||||
.SYNOPSIS
|
||||
Helper function for executing command-line programs.
|
||||
|
||||
.DESCRIPTION
|
||||
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error occcured.
|
||||
If an error is detected then an exception is thrown. This function allows you to run command-line programs without
|
||||
having to explicitly check fthe $lastexitcode variable.
|
||||
|
||||
.PARAMETER cmd
|
||||
The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
|
||||
Required
|
||||
|
||||
.PARAMETER errorMessage
|
||||
The error message used for the exception that is thrown.
|
||||
Optional
|
||||
|
||||
.EXAMPLE
|
||||
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
|
||||
|
||||
This example calls the svn command-line client.
|
||||
|
||||
.LINK
|
||||
Assert
|
||||
Invoke-psake
|
||||
Task
|
||||
Properties
|
||||
Include
|
||||
FormatTaskName
|
||||
TaskSetup
|
||||
TaskTearDown
|
||||
#></span>
|
||||
[<span style="color:PowderBlue;">CmdletBinding</span>()]
|
||||
|
||||
<span style="color:Blue;">param</span>(
|
||||
<span style="color:Gray;">[</span><span style="color:Teal;">Parameter(Position=0,Mandatory=1)</span><span style="color:Gray;">]</span><span style="color:Gray;">[</span><span style="color:Teal;">scriptblock</span><span style="color:Gray;">]</span><span style="color:OrangeRed;">$cmd</span>,
|
||||
<span style="color:Gray;">[</span><span style="color:Teal;">Parameter(Position=1,Mandatory=0)</span><span style="color:Gray;">]</span><span style="color:Gray;">[</span><span style="color:Teal;">string</span><span style="color:Gray;">]</span><span style="color:OrangeRed;">$errorMessage</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">"Error executing command: "</span> <span style="color:Gray;">+</span> <span style="color:OrangeRed;">$cmd</span>
|
||||
)
|
||||
& <span style="color:OrangeRed;">$cmd</span>
|
||||
<span style="color:Blue;">if</span> (<span style="color:OrangeRed;">$lastexitcode</span> <span style="color:Gray;">-ne</span> 0)
|
||||
{
|
||||
<span style="color:Blue;">throw</span> <span style="color:OrangeRed;">$errorMessage</span>
|
||||
}
|
||||
}
|
||||
</pre></div>
|
|
@ -1,47 +0,0 @@
|
|||
#-- Public Module Functions
|
||||
function Exec
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Helper function for executing command-line programs.
|
||||
|
||||
.DESCRIPTION
|
||||
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode to see if an error occcured.
|
||||
If an error is detected then an exception is thrown. This function allows you to run command-line programs without
|
||||
having to explicitly check fthe $lastexitcode variable.
|
||||
|
||||
.PARAMETER cmd
|
||||
The scriptblock to execute. This scriptblock will typically contain the command-line invocation.
|
||||
Required
|
||||
|
||||
.PARAMETER errorMessage
|
||||
The error message used for the exception that is thrown.
|
||||
Optional
|
||||
|
||||
.EXAMPLE
|
||||
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
|
||||
|
||||
This example calls the svn command-line client.
|
||||
|
||||
.LINK
|
||||
Assert
|
||||
Invoke-psake
|
||||
Task
|
||||
Properties
|
||||
Include
|
||||
FormatTaskName
|
||||
TaskSetup
|
||||
TaskTearDown
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
|
||||
param(
|
||||
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
|
||||
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = "Error executing command: " + $cmd
|
||||
)
|
||||
& $cmd
|
||||
if ($lastexitcode -ne 0)
|
||||
{
|
||||
throw $errorMessage
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Gray;">-eq</span>
|
||||
<span style="color:Gray;">-ceq</span>
|
||||
<span style="color:Gray;">-ieq</span>
|
||||
<span style="color:Gray;">-ne</span>
|
||||
<span style="color:Gray;">-cne</span>
|
||||
<span style="color:Gray;">-ine</span>
|
||||
<span style="color:Gray;">-gt</span>
|
||||
<span style="color:Gray;">-cgt</span>
|
||||
<span style="color:Gray;">-igt</span>
|
||||
<span style="color:Gray;">-ge</span>
|
||||
<span style="color:Gray;">-cge</span>
|
||||
<span style="color:Gray;">-ige</span>
|
||||
<span style="color:Gray;">-lt</span>
|
||||
<span style="color:Gray;">-clt</span>
|
||||
<span style="color:Gray;">-ilt</span>
|
||||
<span style="color:Gray;">-le</span>
|
||||
<span style="color:Gray;">-cle</span>
|
||||
<span style="color:Gray;">-ile</span>
|
||||
<span style="color:Gray;">-notlike</span>
|
||||
<span style="color:Gray;">-cnotlike</span>
|
||||
<span style="color:Gray;">-inotlike</span>
|
||||
<span style="color:Gray;">-like</span>
|
||||
<span style="color:Gray;">-clike</span>
|
||||
<span style="color:Gray;">-ilike</span>
|
||||
<span style="color:Gray;">-notmatch</span>
|
||||
<span style="color:Gray;">-cnotmatch</span>
|
||||
<span style="color:Gray;">-inotmatch</span>
|
||||
<span style="color:Gray;">-match</span>
|
||||
<span style="color:Gray;">-cmatch</span>
|
||||
<span style="color:Gray;">-imatch</span>
|
||||
<span style="color:Gray;">-notcontains</span>
|
||||
<span style="color:Gray;">-cnotcontains</span>
|
||||
<span style="color:Gray;">-inotcontains</span>
|
||||
<span style="color:Gray;">-contains</span>
|
||||
<span style="color:Gray;">-ccontains</span>
|
||||
<span style="color:Gray;">-icontains</span>
|
||||
<span style="color:Gray;">-replace</span>
|
||||
<span style="color:Gray;">-creplace</span>
|
||||
<span style="color:Gray;">-ireplace</span>
|
||||
<span style="color:Gray;">-band</span>
|
||||
<span style="color:Gray;">-and</span>
|
||||
<span style="color:Gray;">-as</span>
|
||||
<span style="color:Gray;">-join</span>
|
||||
<span style="color:Gray;">-not</span>
|
||||
<span style="color:Gray;">-bxor</span>
|
||||
<span style="color:Gray;">-xor</span>
|
||||
<span style="color:Gray;">-bor</span>
|
||||
<span style="color:Gray;">-or</span>
|
||||
<span style="color:Gray;">-isnot</span>
|
||||
<span style="color:Gray;">-is</span>
|
||||
<span style="color:Gray;">-split</span>
|
||||
<span style="color:Gray;">+=</span>
|
||||
<span style="color:Gray;">-=</span>
|
||||
<span style="color:Gray;">*=</span>
|
||||
<span style="color:Gray;">/=</span>
|
||||
<span style="color:Gray;">%=</span>
|
||||
<span style="color:Gray;">=</span>
|
||||
<span style="color:Gray;">++</span>
|
||||
<span style="color:Gray;">--</span>
|
||||
<span style="color:Gray;">+</span>
|
||||
<span style="color:Gray;">-</span>
|
||||
<span style="color:Gray;">*</span>
|
||||
<span style="color:Gray;">/</span>
|
||||
<span style="color:Gray;">%</span>
|
||||
<span style="color:Gray;">>></span>
|
||||
<span style="color:Gray;">></span>
|
||||
<span style="color:Gray;">2>></span>
|
||||
<span style="color:Gray;">2></span>
|
||||
<span style="color:Gray;">2>&1</span>
|
||||
</pre></div>
|
|
@ -1,69 +0,0 @@
|
|||
-eq
|
||||
-ceq
|
||||
-ieq
|
||||
-ne
|
||||
-cne
|
||||
-ine
|
||||
-gt
|
||||
-cgt
|
||||
-igt
|
||||
-ge
|
||||
-cge
|
||||
-ige
|
||||
-lt
|
||||
-clt
|
||||
-ilt
|
||||
-le
|
||||
-cle
|
||||
-ile
|
||||
-notlike
|
||||
-cnotlike
|
||||
-inotlike
|
||||
-like
|
||||
-clike
|
||||
-ilike
|
||||
-notmatch
|
||||
-cnotmatch
|
||||
-inotmatch
|
||||
-match
|
||||
-cmatch
|
||||
-imatch
|
||||
-notcontains
|
||||
-cnotcontains
|
||||
-inotcontains
|
||||
-contains
|
||||
-ccontains
|
||||
-icontains
|
||||
-replace
|
||||
-creplace
|
||||
-ireplace
|
||||
-band
|
||||
-and
|
||||
-as
|
||||
-join
|
||||
-not
|
||||
-bxor
|
||||
-xor
|
||||
-bor
|
||||
-or
|
||||
-isnot
|
||||
-is
|
||||
-split
|
||||
+=
|
||||
-=
|
||||
*=
|
||||
/=
|
||||
%=
|
||||
=
|
||||
++
|
||||
--
|
||||
+
|
||||
-
|
||||
*
|
||||
/
|
||||
%
|
||||
>>
|
||||
>
|
||||
2>>
|
||||
2>
|
||||
2>&1
|
|
@ -1,306 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Green;">################################################################################ </span>
|
||||
<span style="color:Green;"># Set-ClipboardScript.ps1 </span>
|
||||
<span style="color:Green;"># </span>
|
||||
<span style="color:Green;"># The script entire contents of the currently selected editor window to system </span>
|
||||
<span style="color:Green;"># clipboard. The copied data can be pasted into any application that supports </span>
|
||||
<span style="color:Green;"># pasting in UnicodeText, RTF or HTML format. Text pasted in RTF or HTML </span>
|
||||
<span style="color:Green;"># format will be colorized. </span>
|
||||
<span style="color:Green;"># </span>
|
||||
<span style="color:Green;"># See also: </span>
|
||||
<span style="color:Green;"># http://blogs.msdn.com/powershell/archive/2009/01/13/ </span>
|
||||
<span style="color:Green;"># how-to-copy-colorized-script-from-powershell-ise.aspx </span>
|
||||
<span style="color:Green;"># http://www.leeholmes.com/blog/SyntaxHighlightingInPowerShell.aspx </span>
|
||||
<span style="color:Green;"># http://www.leeholmes.com/blog/RealtimeSyntaxHighlightingInYourPowerShellConsole.aspx </span>
|
||||
<span style="color:Green;"># </span>
|
||||
<span style="color:Green;">################################################################################ </span>
|
||||
|
||||
[<span style="color:PowderBlue;">CmdletBinding</span>()]
|
||||
<span style="color:Blue;">param</span>(<span style="color:OrangeRed;">$path</span>)
|
||||
|
||||
<span style="color:Blue;">function</span> Get<span style="color:Gray;">-</span>ScriptName
|
||||
{
|
||||
<span style="color:OrangeRed;">$myInvocation</span>.ScriptName
|
||||
}
|
||||
|
||||
<span style="color:Blue;">if</span>(<span style="color:OrangeRed;">$path</span> <span style="color:Gray;">-and</span> (<span style="color:Gray;">[</span><span style="color:Teal;">Threading.Thread</span><span style="color:Gray;">]</span><span style="color:Gray;">::</span>CurrentThread.ApartmentState <span style="color:Gray;">-ne</span> <span style="color:#A31515;">"STA"</span>))
|
||||
{
|
||||
PowerShell <span style="color:Gray;">-</span>NoProfile <span style="color:Gray;">-</span>STA <span style="color:Gray;">-</span>File (Get<span style="color:Gray;">-</span>ScriptName) <span style="color:OrangeRed;">$path</span>
|
||||
<span style="color:Blue;">return</span>
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$tokenColours</span> <span style="color:Gray;">=</span> @{
|
||||
<span style="color:#A31515;">'Attribute'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FFADD8E6'</span>
|
||||
<span style="color:#A31515;">'Command'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF0000FF'</span>
|
||||
<span style="color:#A31515;">'CommandArgument'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF8A2BE2'</span>
|
||||
<span style="color:#A31515;">'CommandParameter'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000080'</span>
|
||||
<span style="color:#A31515;">'Comment'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF006400'</span>
|
||||
<span style="color:#A31515;">'GroupEnd'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'GroupStart'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'Keyword'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF00008B'</span>
|
||||
<span style="color:#A31515;">'LineContinuation'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'LoopLabel'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF00008B'</span>
|
||||
<span style="color:#A31515;">'Member'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'NewLine'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'Number'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF800080'</span>
|
||||
<span style="color:#A31515;">'Operator'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FFA9A9A9'</span>
|
||||
<span style="color:#A31515;">'Position'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'StatementSeparator'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'String'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF8B0000'</span>
|
||||
<span style="color:#A31515;">'Type'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF008080'</span>
|
||||
<span style="color:#A31515;">'Unknown'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FF000000'</span>
|
||||
<span style="color:#A31515;">'Variable'</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'#FFFF4500'</span>
|
||||
}
|
||||
|
||||
<span style="color:Blue;">if</span>(<span style="color:OrangeRed;">$psise</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$tokenColours</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$psise</span>.Options.TokenColors
|
||||
}
|
||||
|
||||
Add<span style="color:Gray;">-</span>Type <span style="color:Gray;">-</span>Assembly System.Web
|
||||
Add<span style="color:Gray;">-</span>Type <span style="color:Gray;">-</span>Assembly PresentationCore
|
||||
|
||||
<span style="color:Green;"># Create RTF block from text using named console colors. </span>
|
||||
<span style="color:Blue;">function</span> Append<span style="color:Gray;">-</span>RtfBlock (<span style="color:OrangeRed;">$block</span>, <span style="color:OrangeRed;">$tokenColor</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$colorIndex</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfColorMap</span>.<span style="color:OrangeRed;">$tokenColor</span>
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$block</span>.Replace(<span style="color:#A31515;">'\','</span>\\').Replace(<span style="color:#A31515;">"`r`n"</span>,<span style="color:#A31515;">"\cf1\par`r`n"</span>)
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$block</span>.Replace(<span style="color:#A31515;">"`t"</span>,<span style="color:#A31515;">'\tab'</span>).Replace(<span style="color:#A31515;">'{'</span>,<span style="color:#A31515;">'\{'</span>).Replace(<span style="color:#A31515;">'}'</span>,<span style="color:#A31515;">'\}'</span>)
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">"\cf$colorIndex $block"</span>)
|
||||
}
|
||||
|
||||
<span style="color:Green;"># Generate an HTML span and append it to HTML string builder </span>
|
||||
<span style="color:OrangeRed;">$currentLine</span> <span style="color:Gray;">=</span> 1
|
||||
<span style="color:Blue;">function</span> Append<span style="color:Gray;">-</span>HtmlSpan (<span style="color:OrangeRed;">$block</span>, <span style="color:OrangeRed;">$tokenColor</span>)
|
||||
{
|
||||
<span style="color:Blue;">if</span> ((<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">-eq</span> <span style="color:#A31515;">'NewLine'</span>) <span style="color:Gray;">-or</span> (<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">-eq</span> <span style="color:#A31515;">'LineContinuation'</span>))
|
||||
{
|
||||
<span style="color:Blue;">if</span>(<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">-eq</span> <span style="color:#A31515;">'LineContinuation'</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$codeBuilder</span>.Append(<span style="color:#A31515;">'`'</span>)
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$codeBuilder</span>.Append(<span style="color:#A31515;">"<br />`r`n"</span>)
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$lineBuilder</span>.Append(<span style="color:#A31515;">"{0:000}<BR />"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$currentLine</span>)
|
||||
<span style="color:OrangeRed;">$SCRIPT:currentLine</span><span style="color:Gray;">++</span>
|
||||
}
|
||||
<span style="color:Blue;">else</span>
|
||||
{
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:Gray;">[</span><span style="color:Teal;">System.Web.HttpUtility</span><span style="color:Gray;">]</span><span style="color:Gray;">::</span>HtmlEncode(<span style="color:OrangeRed;">$block</span>)
|
||||
<span style="color:Blue;">if</span> (<span style="color:Gray;">-not</span> <span style="color:OrangeRed;">$block</span>.Trim())
|
||||
{
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$block</span>.Replace(<span style="color:#A31515;">' '</span>, <span style="color:#A31515;">'&nbsp;'</span>)
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$htmlColor</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$tokenColours</span><span style="color:Gray;">[</span><span style="color:Teal;">$tokenColor</span><span style="color:Gray;">]</span>.ToString().Replace(<span style="color:#A31515;">'#FF'</span>, <span style="color:#A31515;">'#'</span>)
|
||||
|
||||
<span style="color:Blue;">if</span>(<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">-eq</span> <span style="color:#A31515;">'String'</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$lines</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$block</span> <span style="color:Gray;">-split</span> <span style="color:#A31515;">"`r`n"</span>
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">""</span>
|
||||
|
||||
<span style="color:OrangeRed;">$multipleLines</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$false</span>
|
||||
<span style="color:Blue;">foreach</span>(<span style="color:OrangeRed;">$line</span> <span style="color:Blue;">in</span> <span style="color:OrangeRed;">$lines</span>)
|
||||
{
|
||||
<span style="color:Blue;">if</span>(<span style="color:OrangeRed;">$multipleLines</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">+=</span> <span style="color:#A31515;">"<BR />`r`n"</span>
|
||||
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$lineBuilder</span>.Append(<span style="color:#A31515;">"{0:000}<BR />"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$currentLine</span>)
|
||||
<span style="color:OrangeRed;">$SCRIPT:currentLine</span><span style="color:Gray;">++</span>
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$newText</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$line</span>.TrimStart()
|
||||
<span style="color:OrangeRed;">$newText</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">"&nbsp;"</span> <span style="color:Gray;">*</span> (<span style="color:OrangeRed;">$line</span>.Length <span style="color:Gray;">-</span> <span style="color:OrangeRed;">$newText</span>.Length) <span style="color:Gray;">+</span>
|
||||
<span style="color:OrangeRed;">$newText</span>
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">+=</span> <span style="color:OrangeRed;">$newText</span>
|
||||
<span style="color:OrangeRed;">$multipleLines</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$true</span>
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$codeBuilder</span>.Append(
|
||||
<span style="color:#A31515;">"<span style='color:$htmlColor'>$block</span>"</span>)
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:Blue;">function</span> GetHtmlClipboardFormat(<span style="color:OrangeRed;">$html</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">@"
|
||||
Version:1.0
|
||||
StartHTML:0000000000
|
||||
EndHTML:0000000000
|
||||
StartFragment:0000000000
|
||||
EndFragment:0000000000
|
||||
StartSelection:0000000000
|
||||
EndSelection:0000000000
|
||||
SourceURL:file:///about:blank
|
||||
<!DOCTYPE HTML PUBLIC `"-//W3C//DTD HTML 4.0 Transitional//EN`">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>HTML Clipboard</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<!--StartFragment-->
|
||||
<DIV style='font-family:Consolas,Lucida Console; font-size:10pt;
|
||||
width:750; border:1px solid black; overflow:auto; padding:5px'>
|
||||
<TABLE BORDER='0' cellpadding='5' cellspacing='0'>
|
||||
<TBODY>
|
||||
<TR>
|
||||
<TD VALIGN='Top'>
|
||||
<DIV style='font-family:Consolas,Lucida Console; font-size:10pt;
|
||||
padding:5px; background:#cecece'>
|
||||
__LINES__
|
||||
</DIV>
|
||||
</TD>
|
||||
<TD VALIGN='Top' NOWRAP='NOWRAP'>
|
||||
<DIV style='font-family:Consolas,Lucida Console; font-size:10pt;
|
||||
padding:5px; background:#fcfcfc'>
|
||||
__HTML__
|
||||
</DIV>
|
||||
</TD>
|
||||
</TR>
|
||||
</TBODY>
|
||||
</TABLE>
|
||||
</DIV>
|
||||
<!--EndFragment-->
|
||||
</BODY>
|
||||
</HTML>
|
||||
"@</span>
|
||||
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span>.Replace(<span style="color:#A31515;">"__LINES__"</span>, <span style="color:OrangeRed;">$lineBuilder</span>.ToString())
|
||||
<span style="color:OrangeRed;">$startFragment</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span>.IndexOf(<span style="color:#A31515;">"<!--StartFragment-->"</span>) <span style="color:Gray;">+</span>
|
||||
<span style="color:#A31515;">"<!--StartFragment-->"</span>.Length <span style="color:Gray;">+</span> 2
|
||||
<span style="color:OrangeRed;">$endFragment</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span>.IndexOf(<span style="color:#A31515;">"<!--EndFragment-->"</span>) <span style="color:Gray;">+</span>
|
||||
<span style="color:OrangeRed;">$html</span>.Length <span style="color:Gray;">-</span> <span style="color:#A31515;">"__HTML__"</span>.Length
|
||||
<span style="color:OrangeRed;">$startHtml</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span>.IndexOf(<span style="color:#A31515;">"<!DOCTYPE"</span>)
|
||||
<span style="color:OrangeRed;">$endHtml</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span>.Length <span style="color:Gray;">+</span> <span style="color:OrangeRed;">$html</span>.Length <span style="color:Gray;">-</span> <span style="color:#A31515;">"__HTML__"</span>.Length
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span> <span style="color:Gray;">-replace</span> <span style="color:#A31515;">"StartHTML:0000000000"</span>,
|
||||
(<span style="color:#A31515;">"StartHTML:{0:0000000000}"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$startHtml</span>)
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span> <span style="color:Gray;">-replace</span> <span style="color:#A31515;">"EndHTML:0000000000"</span>,
|
||||
(<span style="color:#A31515;">"EndHTML:{0:0000000000}"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$endHtml</span>)
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span> <span style="color:Gray;">-replace</span> <span style="color:#A31515;">"StartFragment:0000000000"</span>,
|
||||
(<span style="color:#A31515;">"StartFragment:{0:0000000000}"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$startFragment</span>)
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span> <span style="color:Gray;">-replace</span> <span style="color:#A31515;">"EndFragment:0000000000"</span>,
|
||||
(<span style="color:#A31515;">"EndFragment:{0:0000000000}"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$endFragment</span>)
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span> <span style="color:Gray;">-replace</span> <span style="color:#A31515;">"StartSelection:0000000000"</span>,
|
||||
(<span style="color:#A31515;">"StartSelection:{0:0000000000}"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$startFragment</span>)
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span> <span style="color:Gray;">-replace</span> <span style="color:#A31515;">"EndSelection:0000000000"</span>,
|
||||
(<span style="color:#A31515;">"EndSelection:{0:0000000000}"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$endFragment</span>)
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$header</span>.Replace(<span style="color:#A31515;">"__HTML__"</span>, <span style="color:OrangeRed;">$html</span>)
|
||||
|
||||
Write<span style="color:Gray;">-</span>Verbose <span style="color:OrangeRed;">$header</span>
|
||||
<span style="color:OrangeRed;">$header</span>
|
||||
}
|
||||
|
||||
<span style="color:Blue;">function</span> Main
|
||||
{
|
||||
<span style="color:OrangeRed;">$text</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$null</span>
|
||||
|
||||
<span style="color:Blue;">if</span>(<span style="color:OrangeRed;">$path</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$text</span> <span style="color:Gray;">=</span> (Get<span style="color:Gray;">-</span>Content <span style="color:OrangeRed;">$path</span>) <span style="color:Gray;">-join</span> <span style="color:#A31515;">"`r`n"</span>
|
||||
}
|
||||
<span style="color:Blue;">else</span>
|
||||
{
|
||||
<span style="color:Blue;">if</span> (<span style="color:Gray;">-not</span> <span style="color:OrangeRed;">$psise</span>.CurrentOpenedFile)
|
||||
{
|
||||
Write<span style="color:Gray;">-</span>Error <span style="color:#A31515;">'No script is available for copying.'</span>
|
||||
<span style="color:Blue;">return</span>
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$text</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$psise</span>.CurrentOpenedFile.Editor.Text
|
||||
}
|
||||
|
||||
<span style="color:Blue;">trap</span> { <span style="color:Blue;">break</span> }
|
||||
|
||||
<span style="color:Green;"># Do syntax parsing. </span>
|
||||
<span style="color:OrangeRed;">$errors</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$null</span>
|
||||
<span style="color:OrangeRed;">$tokens</span> <span style="color:Gray;">=</span> <span style="color:Gray;">[</span><span style="color:Teal;">system.management.automation.psparser</span><span style="color:Gray;">]</span><span style="color:Gray;">::</span>Tokenize(<span style="color:OrangeRed;">$Text</span>,
|
||||
<span style="color:Gray;">[</span><span style="color:Teal;">ref</span><span style="color:Gray;">]</span> <span style="color:OrangeRed;">$errors</span>)
|
||||
|
||||
<span style="color:Green;"># Initialize HTML builder. </span>
|
||||
<span style="color:OrangeRed;">$codeBuilder</span> <span style="color:Gray;">=</span> new<span style="color:Gray;">-</span>object system.text.stringbuilder
|
||||
<span style="color:OrangeRed;">$lineBuilder</span> <span style="color:Gray;">=</span> new<span style="color:Gray;">-</span>object system.text.stringbuilder
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$lineBuilder</span>.Append(<span style="color:#A31515;">"{0:000}<BR />"</span> <span style="color:Gray;">-</span>f <span style="color:OrangeRed;">$currentLine</span>)
|
||||
<span style="color:OrangeRed;">$SCRIPT:currentLine</span><span style="color:Gray;">++</span>
|
||||
|
||||
|
||||
<span style="color:Green;"># Initialize RTF builder. </span>
|
||||
<span style="color:OrangeRed;">$rtfBuilder</span> <span style="color:Gray;">=</span> new<span style="color:Gray;">-</span>object system.text.stringbuilder
|
||||
|
||||
<span style="color:Green;"># Append RTF header </span>
|
||||
<span style="color:OrangeRed;">$header</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">"{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl"</span> <span style="color:Gray;">+</span>
|
||||
<span style="color:#A31515;">"{\f0\fnil\fcharset0 $fontName;}}"</span>
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:OrangeRed;">$header</span>)
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">"`r`n"</span>)
|
||||
|
||||
<span style="color:Green;"># Append RTF color table which will contain all Powershell console colors. </span>
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">"{\colortbl ;"</span>)
|
||||
|
||||
<span style="color:Green;"># Generate RTF color definitions for each token type. </span>
|
||||
<span style="color:OrangeRed;">$rtfColorIndex</span> <span style="color:Gray;">=</span> 1
|
||||
<span style="color:OrangeRed;">$rtfColors</span> <span style="color:Gray;">=</span> @{}
|
||||
<span style="color:OrangeRed;">$rtfColorMap</span> <span style="color:Gray;">=</span> @{}
|
||||
|
||||
<span style="color:Gray;">[</span><span style="color:Teal;">Enum</span><span style="color:Gray;">]</span><span style="color:Gray;">::</span>GetNames(<span style="color:Gray;">[</span><span style="color:Teal;">System.Management.Automation.PSTokenType</span><span style="color:Gray;">]</span>) | <span style="color:Gray;">%</span> {
|
||||
<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$tokenColours</span><span style="color:Gray;">[</span><span style="color:Teal;">$_</span><span style="color:Gray;">]</span>;
|
||||
<span style="color:OrangeRed;">$rtfColor</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">"\red$($tokenColor.R)\green$($tokenColor.G)\blue"</span> <span style="color:Gray;">+</span>
|
||||
<span style="color:#A31515;">"$($tokenColor.B);"</span>
|
||||
<span style="color:Blue;">if</span> (<span style="color:OrangeRed;">$rtfColors</span>.Keys <span style="color:Gray;">-notcontains</span> <span style="color:OrangeRed;">$rtfColor</span>)
|
||||
{
|
||||
<span style="color:OrangeRed;">$rtfColors</span>.<span style="color:OrangeRed;">$rtfColor</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfColorIndex</span>
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:OrangeRed;">$rtfColor</span>)
|
||||
<span style="color:OrangeRed;">$rtfColorMap</span>.<span style="color:OrangeRed;">$_</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfColorIndex</span>
|
||||
<span style="color:OrangeRed;">$rtfColorIndex</span> <span style="color:Gray;">++</span>
|
||||
}
|
||||
<span style="color:Blue;">else</span>
|
||||
{
|
||||
<span style="color:OrangeRed;">$rtfColorMap</span>.<span style="color:OrangeRed;">$_</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfColors</span>.<span style="color:OrangeRed;">$rtfColor</span>
|
||||
}
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">'}'</span>)
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">"`r`n"</span>)
|
||||
|
||||
<span style="color:Green;"># Append RTF document settings. </span>
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">'\viewkind4\uc1\pard\f0\fs20 '</span>)
|
||||
|
||||
<span style="color:Green;"># Iterate over the tokens and set the colors appropriately. </span>
|
||||
<span style="color:OrangeRed;">$position</span> <span style="color:Gray;">=</span> 0
|
||||
<span style="color:Blue;">foreach</span> (<span style="color:OrangeRed;">$token</span> <span style="color:Blue;">in</span> <span style="color:OrangeRed;">$tokens</span>)
|
||||
{
|
||||
<span style="color:Blue;">if</span> (<span style="color:OrangeRed;">$position</span> <span style="color:Gray;">-lt</span> <span style="color:OrangeRed;">$token</span>.Start)
|
||||
{
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$text</span>.Substring(<span style="color:OrangeRed;">$position</span>, (<span style="color:OrangeRed;">$token</span>.Start <span style="color:Gray;">-</span> <span style="color:OrangeRed;">$position</span>))
|
||||
<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">=</span> <span style="color:#A31515;">'Unknown'</span>
|
||||
Append<span style="color:Gray;">-</span>RtfBlock <span style="color:OrangeRed;">$block</span> <span style="color:OrangeRed;">$tokenColor</span>
|
||||
Append<span style="color:Gray;">-</span>HtmlSpan <span style="color:OrangeRed;">$block</span> <span style="color:OrangeRed;">$tokenColor</span>
|
||||
}
|
||||
|
||||
<span style="color:OrangeRed;">$block</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$text</span>.Substring(<span style="color:OrangeRed;">$token</span>.Start, <span style="color:OrangeRed;">$token</span>.Length)
|
||||
<span style="color:OrangeRed;">$tokenColor</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$token</span>.Type.ToString()
|
||||
Append<span style="color:Gray;">-</span>RtfBlock <span style="color:OrangeRed;">$block</span> <span style="color:OrangeRed;">$tokenColor</span>
|
||||
Append<span style="color:Gray;">-</span>HtmlSpan <span style="color:OrangeRed;">$block</span> <span style="color:OrangeRed;">$tokenColor</span>
|
||||
|
||||
<span style="color:OrangeRed;">$position</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$token</span>.Start <span style="color:Gray;">+</span> <span style="color:OrangeRed;">$token</span>.Length
|
||||
}
|
||||
|
||||
<span style="color:Green;"># Append RTF ending brace. </span>
|
||||
<span style="color:OrangeRed;">$null</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.Append(<span style="color:#A31515;">'}'</span>)
|
||||
|
||||
<span style="color:Green;"># Copy console screen buffer contents to clipboard in three formats - </span>
|
||||
<span style="color:Green;"># text, HTML and RTF. </span>
|
||||
<span style="color:OrangeRed;">$dataObject</span> <span style="color:Gray;">=</span> New<span style="color:Gray;">-</span>Object Windows.DataObject
|
||||
<span style="color:OrangeRed;">$dataObject</span>.SetText(<span style="color:Gray;">[</span><span style="color:Teal;">string</span><span style="color:Gray;">]</span><span style="color:OrangeRed;">$text</span>, <span style="color:Gray;">[</span><span style="color:Teal;">Windows.TextDataFormat</span><span style="color:Gray;">]</span><span style="color:#A31515;">"UnicodeText"</span>)
|
||||
<span style="color:OrangeRed;">$rtf</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$rtfBuilder</span>.ToString()
|
||||
<span style="color:OrangeRed;">$dataObject</span>.SetText(<span style="color:Gray;">[</span><span style="color:Teal;">string</span><span style="color:Gray;">]</span><span style="color:OrangeRed;">$rtf</span>, <span style="color:Gray;">[</span><span style="color:Teal;">Windows.TextDataFormat</span><span style="color:Gray;">]</span><span style="color:#A31515;">"Rtf"</span>)
|
||||
<span style="color:OrangeRed;">$code</span> <span style="color:Gray;">=</span> <span style="color:OrangeRed;">$codeBuilder</span>.ToString()
|
||||
<span style="color:OrangeRed;">$html</span> <span style="color:Gray;">=</span> GetHtmlClipboardFormat(<span style="color:OrangeRed;">$code</span>)
|
||||
|
||||
<span style="color:OrangeRed;">$dataObject</span>.SetText(<span style="color:Gray;">[</span><span style="color:Teal;">string</span><span style="color:Gray;">]</span><span style="color:OrangeRed;">$html</span>, <span style="color:Gray;">[</span><span style="color:Teal;">Windows.TextDataFormat</span><span style="color:Gray;">]</span><span style="color:#A31515;">"Html"</span>)
|
||||
|
||||
<span style="color:Gray;">[</span><span style="color:Teal;">Windows.Clipboard</span><span style="color:Gray;">]</span><span style="color:Gray;">::</span>SetDataObject(<span style="color:OrangeRed;">$dataObject</span>, <span style="color:OrangeRed;">$true</span>)
|
||||
}
|
||||
|
||||
. Main
|
||||
</pre></div>
|
|
@ -1,304 +0,0 @@
|
|||
################################################################################
|
||||
# Set-ClipboardScript.ps1
|
||||
#
|
||||
# The script entire contents of the currently selected editor window to system
|
||||
# clipboard. The copied data can be pasted into any application that supports
|
||||
# pasting in UnicodeText, RTF or HTML format. Text pasted in RTF or HTML
|
||||
# format will be colorized.
|
||||
#
|
||||
# See also:
|
||||
# http://blogs.msdn.com/powershell/archive/2009/01/13/
|
||||
# how-to-copy-colorized-script-from-powershell-ise.aspx
|
||||
# http://www.leeholmes.com/blog/SyntaxHighlightingInPowerShell.aspx
|
||||
# http://www.leeholmes.com/blog/RealtimeSyntaxHighlightingInYourPowerShellConsole.aspx
|
||||
#
|
||||
################################################################################
|
||||
|
||||
[CmdletBinding()]
|
||||
param($path)
|
||||
|
||||
function Get-ScriptName
|
||||
{
|
||||
$myInvocation.ScriptName
|
||||
}
|
||||
|
||||
if($path -and ([Threading.Thread]::CurrentThread.ApartmentState -ne "STA"))
|
||||
{
|
||||
PowerShell -NoProfile -STA -File (Get-ScriptName) $path
|
||||
return
|
||||
}
|
||||
|
||||
$tokenColours = @{
|
||||
'Attribute' = '#FFADD8E6'
|
||||
'Command' = '#FF0000FF'
|
||||
'CommandArgument' = '#FF8A2BE2'
|
||||
'CommandParameter' = '#FF000080'
|
||||
'Comment' = '#FF006400'
|
||||
'GroupEnd' = '#FF000000'
|
||||
'GroupStart' = '#FF000000'
|
||||
'Keyword' = '#FF00008B'
|
||||
'LineContinuation' = '#FF000000'
|
||||
'LoopLabel' = '#FF00008B'
|
||||
'Member' = '#FF000000'
|
||||
'NewLine' = '#FF000000'
|
||||
'Number' = '#FF800080'
|
||||
'Operator' = '#FFA9A9A9'
|
||||
'Position' = '#FF000000'
|
||||
'StatementSeparator' = '#FF000000'
|
||||
'String' = '#FF8B0000'
|
||||
'Type' = '#FF008080'
|
||||
'Unknown' = '#FF000000'
|
||||
'Variable' = '#FFFF4500'
|
||||
}
|
||||
|
||||
if($psise)
|
||||
{
|
||||
$tokenColours = $psise.Options.TokenColors
|
||||
}
|
||||
|
||||
Add-Type -Assembly System.Web
|
||||
Add-Type -Assembly PresentationCore
|
||||
|
||||
# Create RTF block from text using named console colors.
|
||||
function Append-RtfBlock ($block, $tokenColor)
|
||||
{
|
||||
$colorIndex = $rtfColorMap.$tokenColor
|
||||
$block = $block.Replace('\','\\').Replace("`r`n","\cf1\par`r`n")
|
||||
$block = $block.Replace("`t",'\tab').Replace('{','\{').Replace('}','\}')
|
||||
$null = $rtfBuilder.Append("\cf$colorIndex $block")
|
||||
}
|
||||
|
||||
# Generate an HTML span and append it to HTML string builder
|
||||
$currentLine = 1
|
||||
function Append-HtmlSpan ($block, $tokenColor)
|
||||
{
|
||||
if (($tokenColor -eq 'NewLine') -or ($tokenColor -eq 'LineContinuation'))
|
||||
{
|
||||
if($tokenColor -eq 'LineContinuation')
|
||||
{
|
||||
$null = $codeBuilder.Append('`')
|
||||
}
|
||||
|
||||
$null = $codeBuilder.Append("<br />`r`n")
|
||||
$null = $lineBuilder.Append("{0:000}<BR />" -f $currentLine)
|
||||
$SCRIPT:currentLine++
|
||||
}
|
||||
else
|
||||
{
|
||||
$block = [System.Web.HttpUtility]::HtmlEncode($block)
|
||||
if (-not $block.Trim())
|
||||
{
|
||||
$block = $block.Replace(' ', ' ')
|
||||
}
|
||||
|
||||
$htmlColor = $tokenColours[$tokenColor].ToString().Replace('#FF', '#')
|
||||
|
||||
if($tokenColor -eq 'String')
|
||||
{
|
||||
$lines = $block -split "`r`n"
|
||||
$block = ""
|
||||
|
||||
$multipleLines = $false
|
||||
foreach($line in $lines)
|
||||
{
|
||||
if($multipleLines)
|
||||
{
|
||||
$block += "<BR />`r`n"
|
||||
|
||||
$null = $lineBuilder.Append("{0:000}<BR />" -f $currentLine)
|
||||
$SCRIPT:currentLine++
|
||||
}
|
||||
|
||||
$newText = $line.TrimStart()
|
||||
$newText = " " * ($line.Length - $newText.Length) +
|
||||
$newText
|
||||
$block += $newText
|
||||
$multipleLines = $true
|
||||
}
|
||||
}
|
||||
|
||||
$null = $codeBuilder.Append(
|
||||
"<span style='color:$htmlColor'>$block</span>")
|
||||
}
|
||||
}
|
||||
|
||||
function GetHtmlClipboardFormat($html)
|
||||
{
|
||||
$header = @"
|
||||
Version:1.0
|
||||
StartHTML:0000000000
|
||||
EndHTML:0000000000
|
||||
StartFragment:0000000000
|
||||
EndFragment:0000000000
|
||||
StartSelection:0000000000
|
||||
EndSelection:0000000000
|
||||
SourceURL:file:///about:blank
|
||||
<!DOCTYPE HTML PUBLIC `"-//W3C//DTD HTML 4.0 Transitional//EN`">
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>HTML Clipboard</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<!--StartFragment-->
|
||||
<DIV style='font-family:Consolas,Lucida Console; font-size:10pt;
|
||||
width:750; border:1px solid black; overflow:auto; padding:5px'>
|
||||
<TABLE BORDER='0' cellpadding='5' cellspacing='0'>
|
||||
<TBODY>
|
||||
<TR>
|
||||
<TD VALIGN='Top'>
|
||||
<DIV style='font-family:Consolas,Lucida Console; font-size:10pt;
|
||||
padding:5px; background:#cecece'>
|
||||
__LINES__
|
||||
</DIV>
|
||||
</TD>
|
||||
<TD VALIGN='Top' NOWRAP='NOWRAP'>
|
||||
<DIV style='font-family:Consolas,Lucida Console; font-size:10pt;
|
||||
padding:5px; background:#fcfcfc'>
|
||||
__HTML__
|
||||
</DIV>
|
||||
</TD>
|
||||
</TR>
|
||||
</TBODY>
|
||||
</TABLE>
|
||||
</DIV>
|
||||
<!--EndFragment-->
|
||||
</BODY>
|
||||
</HTML>
|
||||
"@
|
||||
|
||||
$header = $header.Replace("__LINES__", $lineBuilder.ToString())
|
||||
$startFragment = $header.IndexOf("<!--StartFragment-->") +
|
||||
"<!--StartFragment-->".Length + 2
|
||||
$endFragment = $header.IndexOf("<!--EndFragment-->") +
|
||||
$html.Length - "__HTML__".Length
|
||||
$startHtml = $header.IndexOf("<!DOCTYPE")
|
||||
$endHtml = $header.Length + $html.Length - "__HTML__".Length
|
||||
$header = $header -replace "StartHTML:0000000000",
|
||||
("StartHTML:{0:0000000000}" -f $startHtml)
|
||||
$header = $header -replace "EndHTML:0000000000",
|
||||
("EndHTML:{0:0000000000}" -f $endHtml)
|
||||
$header = $header -replace "StartFragment:0000000000",
|
||||
("StartFragment:{0:0000000000}" -f $startFragment)
|
||||
$header = $header -replace "EndFragment:0000000000",
|
||||
("EndFragment:{0:0000000000}" -f $endFragment)
|
||||
$header = $header -replace "StartSelection:0000000000",
|
||||
("StartSelection:{0:0000000000}" -f $startFragment)
|
||||
$header = $header -replace "EndSelection:0000000000",
|
||||
("EndSelection:{0:0000000000}" -f $endFragment)
|
||||
$header = $header.Replace("__HTML__", $html)
|
||||
|
||||
Write-Verbose $header
|
||||
$header
|
||||
}
|
||||
|
||||
function Main
|
||||
{
|
||||
$text = $null
|
||||
|
||||
if($path)
|
||||
{
|
||||
$text = (Get-Content $path) -join "`r`n"
|
||||
}
|
||||
else
|
||||
{
|
||||
if (-not $psise.CurrentOpenedFile)
|
||||
{
|
||||
Write-Error 'No script is available for copying.'
|
||||
return
|
||||
}
|
||||
|
||||
$text = $psise.CurrentOpenedFile.Editor.Text
|
||||
}
|
||||
|
||||
trap { break }
|
||||
|
||||
# Do syntax parsing.
|
||||
$errors = $null
|
||||
$tokens = [system.management.automation.psparser]::Tokenize($Text,
|
||||
[ref] $errors)
|
||||
|
||||
# Initialize HTML builder.
|
||||
$codeBuilder = new-object system.text.stringbuilder
|
||||
$lineBuilder = new-object system.text.stringbuilder
|
||||
$null = $lineBuilder.Append("{0:000}<BR />" -f $currentLine)
|
||||
$SCRIPT:currentLine++
|
||||
|
||||
|
||||
# Initialize RTF builder.
|
||||
$rtfBuilder = new-object system.text.stringbuilder
|
||||
|
||||
# Append RTF header
|
||||
$header = "{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl" +
|
||||
"{\f0\fnil\fcharset0 $fontName;}}"
|
||||
$null = $rtfBuilder.Append($header)
|
||||
$null = $rtfBuilder.Append("`r`n")
|
||||
|
||||
# Append RTF color table which will contain all Powershell console colors.
|
||||
$null = $rtfBuilder.Append("{\colortbl ;")
|
||||
|
||||
# Generate RTF color definitions for each token type.
|
||||
$rtfColorIndex = 1
|
||||
$rtfColors = @{}
|
||||
$rtfColorMap = @{}
|
||||
|
||||
[Enum]::GetNames([System.Management.Automation.PSTokenType]) | % {
|
||||
$tokenColor = $tokenColours[$_];
|
||||
$rtfColor = "\red$($tokenColor.R)\green$($tokenColor.G)\blue" +
|
||||
"$($tokenColor.B);"
|
||||
if ($rtfColors.Keys -notcontains $rtfColor)
|
||||
{
|
||||
$rtfColors.$rtfColor = $rtfColorIndex
|
||||
$null = $rtfBuilder.Append($rtfColor)
|
||||
$rtfColorMap.$_ = $rtfColorIndex
|
||||
$rtfColorIndex ++
|
||||
}
|
||||
else
|
||||
{
|
||||
$rtfColorMap.$_ = $rtfColors.$rtfColor
|
||||
}
|
||||
}
|
||||
|
||||
$null = $rtfBuilder.Append('}')
|
||||
$null = $rtfBuilder.Append("`r`n")
|
||||
|
||||
# Append RTF document settings.
|
||||
$null = $rtfBuilder.Append('\viewkind4\uc1\pard\f0\fs20 ')
|
||||
|
||||
# Iterate over the tokens and set the colors appropriately.
|
||||
$position = 0
|
||||
foreach ($token in $tokens)
|
||||
{
|
||||
if ($position -lt $token.Start)
|
||||
{
|
||||
$block = $text.Substring($position, ($token.Start - $position))
|
||||
$tokenColor = 'Unknown'
|
||||
Append-RtfBlock $block $tokenColor
|
||||
Append-HtmlSpan $block $tokenColor
|
||||
}
|
||||
|
||||
$block = $text.Substring($token.Start, $token.Length)
|
||||
$tokenColor = $token.Type.ToString()
|
||||
Append-RtfBlock $block $tokenColor
|
||||
Append-HtmlSpan $block $tokenColor
|
||||
|
||||
$position = $token.Start + $token.Length
|
||||
}
|
||||
|
||||
# Append RTF ending brace.
|
||||
$null = $rtfBuilder.Append('}')
|
||||
|
||||
# Copy console screen buffer contents to clipboard in three formats -
|
||||
# text, HTML and RTF.
|
||||
$dataObject = New-Object Windows.DataObject
|
||||
$dataObject.SetText([string]$text, [Windows.TextDataFormat]"UnicodeText")
|
||||
$rtf = $rtfBuilder.ToString()
|
||||
$dataObject.SetText([string]$rtf, [Windows.TextDataFormat]"Rtf")
|
||||
$code = $codeBuilder.ToString()
|
||||
$html = GetHtmlClipboardFormat($code)
|
||||
|
||||
$dataObject.SetText([string]$html, [Windows.TextDataFormat]"Html")
|
||||
|
||||
[Windows.Clipboard]::SetDataObject($dataObject, $true)
|
||||
}
|
||||
|
||||
. Main
|
|
@ -1,130 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">MIN</span>(TaxRate)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesTaxRate;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">MAX</span>(TaxRate)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesTaxRate;
|
||||
GO
|
||||
|
||||
<span style="color:Green;">--Get the checksum value before the column value is changed.</span>
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">CHECKSUM</span>(<span style="color:Magenta;">CAST</span>(Quantity <span style="color:Blue;">AS</span> <span style="color:Blue;">int</span>))
|
||||
<span style="color:Blue;">FROM</span> Production.ProductInventory;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">UPDATE</span> Production.ProductInventory
|
||||
<span style="color:Blue;">SET</span> Quantity=125
|
||||
<span style="color:Blue;">WHERE</span> Quantity=100;
|
||||
GO
|
||||
<span style="color:Green;">--Get the checksum of the modified column.</span>
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">CHECKSUM</span>(<span style="color:Magenta;">CAST</span>(Quantity <span style="color:Blue;">AS</span> <span style="color:Blue;">int</span>))
|
||||
<span style="color:Blue;">FROM</span> Production.ProductInventory;
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">COUNT</span>(<span style="color:Blue;">DISTINCT</span> Title)
|
||||
<span style="color:Blue;">FROM</span> HumanResources.Employee;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">COUNT</span>(*)
|
||||
<span style="color:Blue;">FROM</span> HumanResources.Employee;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">COUNT</span>(*), <span style="color:Magenta;">AVG</span>(Bonus)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson
|
||||
<span style="color:Blue;">WHERE</span> SalesQuota > 25000;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">COUNT_BIG</span>(<span style="color:Blue;">DISTINCT</span> Title)
|
||||
<span style="color:Blue;">FROM</span> HumanResources.Employee;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">COUNT_BIG</span>(*)
|
||||
<span style="color:Blue;">FROM</span> HumanResources.Employee;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">COUNT_BIG</span>(*), <span style="color:Magenta;">AVG</span>(Bonus)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson
|
||||
<span style="color:Blue;">WHERE</span> SalesQuota > 25000;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> Color, <span style="color:Magenta;">SUM</span>(ListPrice), <span style="color:Magenta;">SUM</span>(StandardCost)
|
||||
<span style="color:Blue;">FROM</span> Production.Product
|
||||
<span style="color:Blue;">WHERE</span> Color <span style="color:Blue;">IS</span> <span style="color:Blue;">NOT</span> <span style="color:Blue;">NULL</span> <span style="color:Blue;">AND</span> ListPrice != 0.00 <span style="color:Blue;">AND</span> StyleName <span style="color:Blue;">LIKE</span> <span style="color:#A31515;">'Mountain%'</span>
|
||||
<span style="color:Blue;">GROUP</span> <span style="color:Blue;">BY</span> Color
|
||||
<span style="color:Blue;">ORDER</span> <span style="color:Blue;">BY</span> Color;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> Color, ListPrice, StandardCost
|
||||
<span style="color:Blue;">FROM</span> Production.Product
|
||||
<span style="color:Blue;">WHERE</span> Color <span style="color:Blue;">IS</span> <span style="color:Blue;">NOT</span> <span style="color:Blue;">NULL</span> <span style="color:Blue;">AND</span> ListPrice != 0.00 <span style="color:Blue;">AND</span> StyleName <span style="color:Blue;">LIKE</span> <span style="color:#A31515;">'Mountain%'</span>
|
||||
<span style="color:Blue;">ORDER</span> <span style="color:Blue;">BY</span> Color
|
||||
<span style="color:Blue;">COMPUTE</span> <span style="color:Magenta;">SUM</span>(ListPrice), <span style="color:Magenta;">SUM</span>(StandardCost) <span style="color:Blue;">BY</span> Color;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> Color, <span style="color:Magenta;">SUM</span>(ListPrice), <span style="color:Magenta;">SUM</span>(StandardCost)
|
||||
<span style="color:Blue;">FROM</span> Production.Product
|
||||
<span style="color:Blue;">GROUP</span> <span style="color:Blue;">BY</span> Color
|
||||
<span style="color:Blue;">ORDER</span> <span style="color:Blue;">BY</span> Color
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> SalesQuota, <span style="color:Magenta;">SUM</span>(SalesYTD) <span style="color:#A31515;">'TotalSalesYTD'</span>, <span style="color:Magenta;">GROUPING</span>(SalesQuota) <span style="color:Blue;">AS</span> <span style="color:#A31515;">'Grouping'</span>
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson
|
||||
<span style="color:Blue;">GROUP</span> <span style="color:Blue;">BY</span> SalesQuota <span style="color:Blue;">WITH</span> <span style="color:Blue;">ROLLUP</span>;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">STDEV</span>(Bonus)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">STDEVP</span>(Bonus)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">VAR</span>(Bonus)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">VARP</span>(Bonus)
|
||||
<span style="color:Blue;">FROM</span> Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> TitleID, <span style="color:Magenta;">BINARY_CHECKSUM</span>(*)
|
||||
<span style="color:Blue;">FROM</span> Pubs.dbo.titles GO <span style="color:Blue;">SELECT</span> EmployeeID, <span style="color:Magenta;">BINARY_CHECKSUM</span>(*)
|
||||
<span style="color:Blue;">FROM</span> AdventureWorks.HumanResources.Employee;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Blue;">absolute</span>(10)
|
||||
</pre></div>
|
|
@ -1,128 +0,0 @@
|
|||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT MIN(TaxRate)
|
||||
FROM Sales.SalesTaxRate;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT MAX(TaxRate)
|
||||
FROM Sales.SalesTaxRate;
|
||||
GO
|
||||
|
||||
--Get the checksum value before the column value is changed.
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT CHECKSUM(CAST(Quantity AS int))
|
||||
FROM Production.ProductInventory;
|
||||
GO
|
||||
|
||||
UPDATE Production.ProductInventory
|
||||
SET Quantity=125
|
||||
WHERE Quantity=100;
|
||||
GO
|
||||
--Get the checksum of the modified column.
|
||||
SELECT CHECKSUM(CAST(Quantity AS int))
|
||||
FROM Production.ProductInventory;
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT COUNT(DISTINCT Title)
|
||||
FROM HumanResources.Employee;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT COUNT(*)
|
||||
FROM HumanResources.Employee;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT COUNT(*), AVG(Bonus)
|
||||
FROM Sales.SalesPerson
|
||||
WHERE SalesQuota > 25000;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT COUNT_BIG(DISTINCT Title)
|
||||
FROM HumanResources.Employee;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT COUNT_BIG(*)
|
||||
FROM HumanResources.Employee;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT COUNT_BIG(*), AVG(Bonus)
|
||||
FROM Sales.SalesPerson
|
||||
WHERE SalesQuota > 25000;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT Color, SUM(ListPrice), SUM(StandardCost)
|
||||
FROM Production.Product
|
||||
WHERE Color IS NOT NULL AND ListPrice != 0.00 AND StyleName LIKE 'Mountain%'
|
||||
GROUP BY Color
|
||||
ORDER BY Color;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT Color, ListPrice, StandardCost
|
||||
FROM Production.Product
|
||||
WHERE Color IS NOT NULL AND ListPrice != 0.00 AND StyleName LIKE 'Mountain%'
|
||||
ORDER BY Color
|
||||
COMPUTE SUM(ListPrice), SUM(StandardCost) BY Color;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT Color, SUM(ListPrice), SUM(StandardCost)
|
||||
FROM Production.Product
|
||||
GROUP BY Color
|
||||
ORDER BY Color
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT SalesQuota, SUM(SalesYTD) 'TotalSalesYTD', GROUPING(SalesQuota) AS 'Grouping'
|
||||
FROM Sales.SalesPerson
|
||||
GROUP BY SalesQuota WITH ROLLUP;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT STDEV(Bonus)
|
||||
FROM Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT STDEVP(Bonus)
|
||||
FROM Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT VAR(Bonus)
|
||||
FROM Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT VARP(Bonus)
|
||||
FROM Sales.SalesPerson;
|
||||
GO
|
||||
|
||||
SELECT TitleID, BINARY_CHECKSUM(*)
|
||||
FROM Pubs.dbo.titles GO SELECT EmployeeID, BINARY_CHECKSUM(*)
|
||||
FROM AdventureWorks.HumanResources.Employee;
|
||||
GO
|
||||
|
||||
SELECT absolute(10)
|
|
@ -1,259 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">ADA</span>
|
||||
<span style="color:Blue;">ADD</span>
|
||||
<span style="color:Blue;">AFTER</span>
|
||||
<span style="color:Blue;">ALL</span>
|
||||
<span style="color:Blue;">ALTER</span>
|
||||
<span style="color:Blue;">AND</span>
|
||||
<span style="color:Blue;">ANY</span>
|
||||
<span style="color:Blue;">AS</span>
|
||||
<span style="color:Blue;">ASC</span>
|
||||
<span style="color:Blue;">AT</span>
|
||||
<span style="color:Blue;">AUTHORIZATION</span>
|
||||
<span style="color:Blue;">AUTO</span>
|
||||
<span style="color:Blue;">BACKUP</span>
|
||||
<span style="color:Blue;">BEGIN</span>
|
||||
<span style="color:Blue;">BETWEEN</span>
|
||||
<span style="color:Blue;">BINARY</span>
|
||||
<span style="color:Blue;">BIT</span>
|
||||
<span style="color:Blue;">BIT_LENGTH</span>
|
||||
<span style="color:Blue;">BREAK</span>
|
||||
<span style="color:Blue;">BROWSE</span>
|
||||
<span style="color:Blue;">BULK</span>
|
||||
<span style="color:Blue;">BY</span>
|
||||
<span style="color:Blue;">CASCADE</span>
|
||||
<span style="color:Blue;">CASE</span>
|
||||
<span style="color:Blue;">CHAR</span>
|
||||
<span style="color:Blue;">CHARACTER</span>
|
||||
<span style="color:Blue;">CHARACTER_LENGTH</span>
|
||||
<span style="color:Blue;">CHAR_LENGTH</span>
|
||||
<span style="color:Blue;">CHECK</span>
|
||||
<span style="color:Blue;">CHECKPOINT</span>
|
||||
<span style="color:Blue;">CLOSE</span>
|
||||
<span style="color:Blue;">CLUSTERED</span>
|
||||
<span style="color:Blue;">COLLATE</span>
|
||||
<span style="color:Blue;">COLUMN</span>
|
||||
<span style="color:Blue;">COMMIT</span>
|
||||
<span style="color:Blue;">COMPUTE</span>
|
||||
<span style="color:Blue;">CONNECT</span>
|
||||
<span style="color:Blue;">CONNECTION</span>
|
||||
<span style="color:Blue;">CONSTRAINT</span>
|
||||
<span style="color:Blue;">CONTAINS</span>
|
||||
<span style="color:Blue;">CONTAINSTABLE</span>
|
||||
<span style="color:Blue;">CONTINUE</span>
|
||||
<span style="color:Blue;">CREATE</span>
|
||||
<span style="color:Blue;">CROSS</span>
|
||||
<span style="color:Blue;">CUBE</span>
|
||||
<span style="color:Blue;">CURRENT</span>
|
||||
<span style="color:Blue;">CURRENT_DATE</span>
|
||||
<span style="color:Blue;">CURRENT_TIME</span>
|
||||
<span style="color:Blue;">CURSOR</span>
|
||||
<span style="color:Blue;">DATABASE</span>
|
||||
<span style="color:Blue;">DATE</span>
|
||||
<span style="color:Blue;">DATETIME</span>
|
||||
<span style="color:Blue;">DBCC</span>
|
||||
<span style="color:Blue;">DEALLOCATE</span>
|
||||
<span style="color:Blue;">DEC</span>
|
||||
<span style="color:Blue;">DECIMAL</span>
|
||||
<span style="color:Blue;">DECLARE</span>
|
||||
<span style="color:Blue;">DEFAULT</span>
|
||||
<span style="color:Blue;">DEFERRED</span>
|
||||
<span style="color:Blue;">DELETE</span>
|
||||
<span style="color:Blue;">DENY</span>
|
||||
<span style="color:Blue;">DESC</span>
|
||||
<span style="color:Blue;">DISK</span>
|
||||
<span style="color:Blue;">DISTINCT</span>
|
||||
<span style="color:Blue;">DISTRIBUTED</span>
|
||||
<span style="color:Blue;">DOUBLE</span>
|
||||
<span style="color:Blue;">DROP</span>
|
||||
<span style="color:Blue;">DUMMY</span>
|
||||
<span style="color:Blue;">DUMP</span>
|
||||
<span style="color:Blue;">ELSE</span>
|
||||
<span style="color:Blue;">ENCRYPTION</span>
|
||||
<span style="color:Blue;">END</span>
|
||||
<span style="color:Blue;">END-EXEC</span>
|
||||
<span style="color:Blue;">ERRLVL</span>
|
||||
<span style="color:Blue;">ESCAPE</span>
|
||||
<span style="color:Blue;">EXCEPT</span>
|
||||
<span style="color:Blue;">EXEC</span>
|
||||
<span style="color:Blue;">EXECUTE</span>
|
||||
<span style="color:Blue;">EXISTS</span>
|
||||
<span style="color:Blue;">EXIT</span>
|
||||
<span style="color:Blue;">EXTERNAL</span>
|
||||
<span style="color:Blue;">EXTRACT</span>
|
||||
<span style="color:Blue;">FALSE</span>
|
||||
<span style="color:Blue;">FETCH</span>
|
||||
<span style="color:Blue;">FILE</span>
|
||||
<span style="color:Blue;">FILLFACTOR</span>
|
||||
<span style="color:Blue;">FIRST</span>
|
||||
<span style="color:Blue;">FLOAT</span>
|
||||
<span style="color:Blue;">FOR</span>
|
||||
<span style="color:Blue;">FOREIGN</span>
|
||||
<span style="color:Blue;">FORTRAN</span>
|
||||
<span style="color:Blue;">FREE</span>
|
||||
<span style="color:Blue;">FREETEXT</span>
|
||||
<span style="color:Blue;">FREETEXTTABLE</span>
|
||||
<span style="color:Blue;">FROM</span>
|
||||
<span style="color:Blue;">FULL</span>
|
||||
<span style="color:Blue;">FUNCTION</span>
|
||||
<span style="color:Blue;">GLOBAL</span>
|
||||
<span style="color:Blue;">GOTO</span>
|
||||
<span style="color:Blue;">GRANT</span>
|
||||
<span style="color:Blue;">GROUP</span>
|
||||
<span style="color:Blue;">HAVING</span>
|
||||
<span style="color:Blue;">HOLDLOCK</span>
|
||||
<span style="color:Blue;">HOUR</span>
|
||||
<span style="color:Blue;">IDENTITY</span>
|
||||
<span style="color:Blue;">IDENTITYCOL</span>
|
||||
<span style="color:Blue;">IDENTITY_INSERT</span>
|
||||
<span style="color:Blue;">IF</span>
|
||||
<span style="color:Blue;">IGNORE</span>
|
||||
<span style="color:Blue;">IMAGE</span>
|
||||
<span style="color:Blue;">IMMEDIATE</span>
|
||||
<span style="color:Blue;">IN</span>
|
||||
<span style="color:Blue;">INCLUDE</span>
|
||||
<span style="color:Blue;">INDEX</span>
|
||||
<span style="color:Blue;">INNER</span>
|
||||
<span style="color:Blue;">INSENSITIVE</span>
|
||||
<span style="color:Blue;">INSERT</span>
|
||||
<span style="color:Blue;">INSTEAD</span>
|
||||
<span style="color:Blue;">INT</span>
|
||||
<span style="color:Blue;">INTEGER</span>
|
||||
<span style="color:Blue;">INTERSECT</span>
|
||||
<span style="color:Blue;">INTO</span>
|
||||
<span style="color:Blue;">IS</span>
|
||||
<span style="color:Blue;">ISOLATION</span>
|
||||
<span style="color:Blue;">JOIN</span>
|
||||
<span style="color:Blue;">KEY</span>
|
||||
<span style="color:Blue;">KILL</span>
|
||||
<span style="color:Blue;">LANGUAGE</span>
|
||||
<span style="color:Blue;">LAST</span>
|
||||
<span style="color:Blue;">LEFT</span>
|
||||
<span style="color:Blue;">LEVEL</span>
|
||||
<span style="color:Blue;">LIKE</span>
|
||||
<span style="color:Blue;">LINENO</span>
|
||||
<span style="color:Blue;">LOAD</span>
|
||||
<span style="color:Blue;">LOCAL</span>
|
||||
<span style="color:Blue;">MINUTE</span>
|
||||
<span style="color:Blue;">MODIFY</span>
|
||||
<span style="color:Blue;">MONEY</span>
|
||||
<span style="color:Blue;">NAME</span>
|
||||
<span style="color:Blue;">NATIONAL</span>
|
||||
<span style="color:Blue;">NCHAR</span>
|
||||
<span style="color:Blue;">NEXT</span>
|
||||
<span style="color:Blue;">NOCHECK</span>
|
||||
<span style="color:Blue;">NOCOUNT</span>
|
||||
<span style="color:Blue;">NONCLUSTERED</span>
|
||||
<span style="color:Blue;">NONE</span>
|
||||
<span style="color:Blue;">NOT</span>
|
||||
<span style="color:Blue;">NULL</span>
|
||||
<span style="color:Blue;">NUMERIC</span>
|
||||
<span style="color:Blue;">NVARCHAR</span>
|
||||
<span style="color:Blue;">OCTET_LENGTH</span>
|
||||
<span style="color:Blue;">OF</span>
|
||||
<span style="color:Blue;">OFF</span>
|
||||
<span style="color:Blue;">OFFSETS</span>
|
||||
<span style="color:Blue;">ON</span>
|
||||
<span style="color:Blue;">ONLY</span>
|
||||
<span style="color:Blue;">OPEN</span>
|
||||
<span style="color:Blue;">OPENDATASOURCE</span>
|
||||
<span style="color:Blue;">OPENQUERY</span>
|
||||
<span style="color:Blue;">OPENROWSET</span>
|
||||
<span style="color:Blue;">OPENXML</span>
|
||||
<span style="color:Blue;">OPTION</span>
|
||||
<span style="color:Blue;">OR</span>
|
||||
<span style="color:Blue;">ORDER</span>
|
||||
<span style="color:Blue;">OUTER</span>
|
||||
<span style="color:Blue;">OUTPUT</span>
|
||||
<span style="color:Blue;">OVER</span>
|
||||
<span style="color:Blue;">OVERLAPS</span>
|
||||
<span style="color:Blue;">PARTIAL</span>
|
||||
<span style="color:Blue;">PASCAL</span>
|
||||
<span style="color:Blue;">PERCENT</span>
|
||||
<span style="color:Blue;">PLAN</span>
|
||||
<span style="color:Blue;">POSITION</span>
|
||||
<span style="color:Blue;">PRECISION</span>
|
||||
<span style="color:Blue;">PREPARE</span>
|
||||
<span style="color:Blue;">PRIMARY</span>
|
||||
<span style="color:Blue;">PRINT</span>
|
||||
<span style="color:Blue;">PRIOR</span>
|
||||
<span style="color:Blue;">PRIVILEGES</span>
|
||||
<span style="color:Blue;">PROC</span>
|
||||
<span style="color:Blue;">PROCEDURE</span>
|
||||
<span style="color:Blue;">PUBLIC</span>
|
||||
<span style="color:Blue;">RAISERROR</span>
|
||||
<span style="color:Blue;">READ</span>
|
||||
<span style="color:Blue;">READTEXT</span>
|
||||
<span style="color:Blue;">REAL</span>
|
||||
<span style="color:Blue;">RECONFIGURE</span>
|
||||
<span style="color:Blue;">REFERENCES</span>
|
||||
<span style="color:Blue;">REPLICATION</span>
|
||||
<span style="color:Blue;">RESTORE</span>
|
||||
<span style="color:Blue;">RESTRICT</span>
|
||||
<span style="color:Blue;">RETURN</span>
|
||||
<span style="color:Blue;">RETURNS</span>
|
||||
<span style="color:Blue;">REVERT</span>
|
||||
<span style="color:Blue;">REVOKE</span>
|
||||
<span style="color:Blue;">RIGHT</span>
|
||||
<span style="color:Blue;">ROLLBACK</span>
|
||||
<span style="color:Blue;">ROLLUP</span>
|
||||
<span style="color:Blue;">ROWCOUNT</span>
|
||||
<span style="color:Blue;">ROWGUIDCOL</span>
|
||||
<span style="color:Blue;">ROWS</span>
|
||||
<span style="color:Blue;">RULE</span>
|
||||
<span style="color:Blue;">SAVE</span>
|
||||
<span style="color:Blue;">SCHEMA</span>
|
||||
<span style="color:Blue;">SCROLL</span>
|
||||
<span style="color:Blue;">SECOND</span>
|
||||
<span style="color:Blue;">SECTION</span>
|
||||
<span style="color:Blue;">SELECT</span>
|
||||
<span style="color:Blue;">SEQUENCE</span>
|
||||
<span style="color:Blue;">SET</span>
|
||||
<span style="color:Blue;">SETUSER</span>
|
||||
<span style="color:Blue;">SHUTDOWN</span>
|
||||
<span style="color:Blue;">SIZE</span>
|
||||
<span style="color:Blue;">SMALLINT</span>
|
||||
<span style="color:Blue;">SMALLMONEY</span>
|
||||
<span style="color:Blue;">SOME</span>
|
||||
<span style="color:Blue;">SQLCA</span>
|
||||
<span style="color:Blue;">SQLERROR</span>
|
||||
<span style="color:Blue;">STATISTICS</span>
|
||||
<span style="color:Blue;">TABLE</span>
|
||||
<span style="color:Blue;">TEMPORARY</span>
|
||||
<span style="color:Blue;">TEXT</span>
|
||||
<span style="color:Blue;">TEXTSIZE</span>
|
||||
<span style="color:Blue;">THEN</span>
|
||||
<span style="color:Blue;">TIME</span>
|
||||
<span style="color:Blue;">TIMESTAMP</span>
|
||||
<span style="color:Blue;">TO</span>
|
||||
<span style="color:Blue;">TOP</span>
|
||||
<span style="color:Blue;">TRAN</span>
|
||||
<span style="color:Blue;">TRANSACTION</span>
|
||||
<span style="color:Blue;">TRANSLATION</span>
|
||||
<span style="color:Blue;">TRIGGER</span>
|
||||
<span style="color:Blue;">TRUE</span>
|
||||
<span style="color:Blue;">TRUNCATE</span>
|
||||
<span style="color:Blue;">TSEQUAL</span>
|
||||
<span style="color:Blue;">UNION</span>
|
||||
<span style="color:Blue;">UNIQUE</span>
|
||||
<span style="color:Blue;">UPDATE</span>
|
||||
<span style="color:Blue;">UPDATETEXT</span>
|
||||
<span style="color:Blue;">USE</span>
|
||||
<span style="color:Blue;">VALUES</span>
|
||||
<span style="color:Blue;">VARCHAR</span>
|
||||
<span style="color:Blue;">VARYING</span>
|
||||
<span style="color:Blue;">VIEW</span>
|
||||
<span style="color:Blue;">WAITFOR</span>
|
||||
<span style="color:Blue;">WHEN</span>
|
||||
<span style="color:Blue;">WHERE</span>
|
||||
<span style="color:Blue;">WHILE</span>
|
||||
<span style="color:Blue;">WITH</span>
|
||||
<span style="color:Blue;">WORK</span>
|
||||
<span style="color:Blue;">WRITETEXT</span>
|
||||
<span style="color:Blue;">BIGINT</span>
|
||||
<span style="color:Blue;">TINYINT</span>
|
||||
<span style="color:Blue;">SMALLDATETIME</span>
|
||||
<span style="color:Blue;">NTEXT</span>
|
||||
<span style="color:Blue;">XML</span>
|
||||
<span style="color:Blue;">TYPE</span>
|
||||
</pre></div>
|
|
@ -1,257 +0,0 @@
|
|||
ADA
|
||||
ADD
|
||||
AFTER
|
||||
ALL
|
||||
ALTER
|
||||
AND
|
||||
ANY
|
||||
AS
|
||||
ASC
|
||||
AT
|
||||
AUTHORIZATION
|
||||
AUTO
|
||||
BACKUP
|
||||
BEGIN
|
||||
BETWEEN
|
||||
BINARY
|
||||
BIT
|
||||
BIT_LENGTH
|
||||
BREAK
|
||||
BROWSE
|
||||
BULK
|
||||
BY
|
||||
CASCADE
|
||||
CASE
|
||||
CHAR
|
||||
CHARACTER
|
||||
CHARACTER_LENGTH
|
||||
CHAR_LENGTH
|
||||
CHECK
|
||||
CHECKPOINT
|
||||
CLOSE
|
||||
CLUSTERED
|
||||
COLLATE
|
||||
COLUMN
|
||||
COMMIT
|
||||
COMPUTE
|
||||
CONNECT
|
||||
CONNECTION
|
||||
CONSTRAINT
|
||||
CONTAINS
|
||||
CONTAINSTABLE
|
||||
CONTINUE
|
||||
CREATE
|
||||
CROSS
|
||||
CUBE
|
||||
CURRENT
|
||||
CURRENT_DATE
|
||||
CURRENT_TIME
|
||||
CURSOR
|
||||
DATABASE
|
||||
DATE
|
||||
DATETIME
|
||||
DBCC
|
||||
DEALLOCATE
|
||||
DEC
|
||||
DECIMAL
|
||||
DECLARE
|
||||
DEFAULT
|
||||
DEFERRED
|
||||
DELETE
|
||||
DENY
|
||||
DESC
|
||||
DISK
|
||||
DISTINCT
|
||||
DISTRIBUTED
|
||||
DOUBLE
|
||||
DROP
|
||||
DUMMY
|
||||
DUMP
|
||||
ELSE
|
||||
ENCRYPTION
|
||||
END
|
||||
END-EXEC
|
||||
ERRLVL
|
||||
ESCAPE
|
||||
EXCEPT
|
||||
EXEC
|
||||
EXECUTE
|
||||
EXISTS
|
||||
EXIT
|
||||
EXTERNAL
|
||||
EXTRACT
|
||||
FALSE
|
||||
FETCH
|
||||
FILE
|
||||
FILLFACTOR
|
||||
FIRST
|
||||
FLOAT
|
||||
FOR
|
||||
FOREIGN
|
||||
FORTRAN
|
||||
FREE
|
||||
FREETEXT
|
||||
FREETEXTTABLE
|
||||
FROM
|
||||
FULL
|
||||
FUNCTION
|
||||
GLOBAL
|
||||
GOTO
|
||||
GRANT
|
||||
GROUP
|
||||
HAVING
|
||||
HOLDLOCK
|
||||
HOUR
|
||||
IDENTITY
|
||||
IDENTITYCOL
|
||||
IDENTITY_INSERT
|
||||
IF
|
||||
IGNORE
|
||||
IMAGE
|
||||
IMMEDIATE
|
||||
IN
|
||||
INCLUDE
|
||||
INDEX
|
||||
INNER
|
||||
INSENSITIVE
|
||||
INSERT
|
||||
INSTEAD
|
||||
INT
|
||||
INTEGER
|
||||
INTERSECT
|
||||
INTO
|
||||
IS
|
||||
ISOLATION
|
||||
JOIN
|
||||
KEY
|
||||
KILL
|
||||
LANGUAGE
|
||||
LAST
|
||||
LEFT
|
||||
LEVEL
|
||||
LIKE
|
||||
LINENO
|
||||
LOAD
|
||||
LOCAL
|
||||
MINUTE
|
||||
MODIFY
|
||||
MONEY
|
||||
NAME
|
||||
NATIONAL
|
||||
NCHAR
|
||||
NEXT
|
||||
NOCHECK
|
||||
NOCOUNT
|
||||
NONCLUSTERED
|
||||
NONE
|
||||
NOT
|
||||
NULL
|
||||
NUMERIC
|
||||
NVARCHAR
|
||||
OCTET_LENGTH
|
||||
OF
|
||||
OFF
|
||||
OFFSETS
|
||||
ON
|
||||
ONLY
|
||||
OPEN
|
||||
OPENDATASOURCE
|
||||
OPENQUERY
|
||||
OPENROWSET
|
||||
OPENXML
|
||||
OPTION
|
||||
OR
|
||||
ORDER
|
||||
OUTER
|
||||
OUTPUT
|
||||
OVER
|
||||
OVERLAPS
|
||||
PARTIAL
|
||||
PASCAL
|
||||
PERCENT
|
||||
PLAN
|
||||
POSITION
|
||||
PRECISION
|
||||
PREPARE
|
||||
PRIMARY
|
||||
PRINT
|
||||
PRIOR
|
||||
PRIVILEGES
|
||||
PROC
|
||||
PROCEDURE
|
||||
PUBLIC
|
||||
RAISERROR
|
||||
READ
|
||||
READTEXT
|
||||
REAL
|
||||
RECONFIGURE
|
||||
REFERENCES
|
||||
REPLICATION
|
||||
RESTORE
|
||||
RESTRICT
|
||||
RETURN
|
||||
RETURNS
|
||||
REVERT
|
||||
REVOKE
|
||||
RIGHT
|
||||
ROLLBACK
|
||||
ROLLUP
|
||||
ROWCOUNT
|
||||
ROWGUIDCOL
|
||||
ROWS
|
||||
RULE
|
||||
SAVE
|
||||
SCHEMA
|
||||
SCROLL
|
||||
SECOND
|
||||
SECTION
|
||||
SELECT
|
||||
SEQUENCE
|
||||
SET
|
||||
SETUSER
|
||||
SHUTDOWN
|
||||
SIZE
|
||||
SMALLINT
|
||||
SMALLMONEY
|
||||
SOME
|
||||
SQLCA
|
||||
SQLERROR
|
||||
STATISTICS
|
||||
TABLE
|
||||
TEMPORARY
|
||||
TEXT
|
||||
TEXTSIZE
|
||||
THEN
|
||||
TIME
|
||||
TIMESTAMP
|
||||
TO
|
||||
TOP
|
||||
TRAN
|
||||
TRANSACTION
|
||||
TRANSLATION
|
||||
TRIGGER
|
||||
TRUE
|
||||
TRUNCATE
|
||||
TSEQUAL
|
||||
UNION
|
||||
UNIQUE
|
||||
UPDATE
|
||||
UPDATETEXT
|
||||
USE
|
||||
VALUES
|
||||
VARCHAR
|
||||
VARYING
|
||||
VIEW
|
||||
WAITFOR
|
||||
WHEN
|
||||
WHERE
|
||||
WHILE
|
||||
WITH
|
||||
WORK
|
||||
WRITETEXT
|
||||
BIGINT
|
||||
TINYINT
|
||||
SMALLDATETIME
|
||||
NTEXT
|
||||
XML
|
||||
TYPE
|
|
@ -1,124 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">ABS</span>(-1.0), <span style="color:Magenta;">ABS</span>(0.0), <span style="color:Magenta;">ABS</span>(1.0)
|
||||
|
||||
<span style="color:Blue;">SET</span> <span style="color:Blue;">NOCOUNT</span> <span style="color:Blue;">OFF</span>;
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>;
|
||||
<span style="color:Blue;">SET</span> @angle = -1.0;
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ACOS of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ACOS</span>(@angle));
|
||||
|
||||
<span style="color:Green;">/* The first value will be -1.01. This fails because the value is
|
||||
outside the range.*/</span>
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @angle = -1.01
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ASIN of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ASIN</span>(@angle))
|
||||
GO
|
||||
|
||||
<span style="color:Green;">-- The next value is -1.00.</span>
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @angle = -1.00
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ASIN of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ASIN</span>(@angle))
|
||||
GO
|
||||
|
||||
<span style="color:Green;">-- The next value is 0.1472738.</span>
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @angle = 0.1472738
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ASIN of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ASIN</span>(@angle))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ATAN of -45.01 is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ATAN</span>(-45.01))
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ATAN of -181.01 is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ATAN</span>(-181.01))
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ATAN of 0 is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ATAN</span>(0))
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ATAN of 0.1472738 is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ATAN</span>(0.1472738))
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ATAN of 197.1099392 is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">ATAN</span>(197.1099392))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @x <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">DECLARE</span> @y <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @x = 35.175643
|
||||
<span style="color:Blue;">SET</span> @y = 129.44
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The ATN2 of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>,<span style="color:Magenta;">ATN2</span>(@x,@y ))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">CEILING</span>($123.45), <span style="color:Magenta;">CEILING</span>($-123.45), <span style="color:Magenta;">CEILING</span>($0.0)
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @angle = 14.78
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The COS of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>,<span style="color:Magenta;">COS</span>(@angle))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @angle = 124.1332
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The COT of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>,<span style="color:Magenta;">COT</span>(@angle))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The number of degrees in PI/2 radians is: '</span> +
|
||||
<span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">DEGREES</span>((<span style="color:Magenta;">PI</span>()/2)));
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @var <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @var = 10
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The EXP of the variable is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>,<span style="color:Magenta;">EXP</span>(@var))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">FLOOR</span>(123.45), <span style="color:Magenta;">FLOOR</span>(-123.45), <span style="color:Magenta;">FLOOR</span>($123.45)
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @var <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @var = 10
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The LOG of the variable is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>, <span style="color:Magenta;">LOG</span>(@var))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @var <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @var = 145.175643
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The LOG10 of the variable is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>,<span style="color:Magenta;">LOG10</span>(@var))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">PI</span>()
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">POWER</span>(2.0, -100.0)
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">RADIANS</span>(1e-307)
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @counter <span style="color:Blue;">smallint</span>
|
||||
<span style="color:Blue;">SET</span> @counter = 1
|
||||
<span style="color:Blue;">WHILE</span> @counter < 5
|
||||
<span style="color:Blue;">BEGIN</span>
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">RAND</span>() Random_Number
|
||||
<span style="color:Blue;">SET</span> @counter = @counter + 1
|
||||
<span style="color:Blue;">END</span>
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">ROUND</span>(123.9994, 3), <span style="color:Magenta;">ROUND</span>(123.9995, 3)
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @value <span style="color:Blue;">real</span>
|
||||
<span style="color:Blue;">SET</span> @value = -1
|
||||
<span style="color:Blue;">WHILE</span> @value < 2
|
||||
<span style="color:Blue;">BEGIN</span>
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">SIGN</span>(@value)
|
||||
<span style="color:Blue;">SET</span> <span style="color:Blue;">NOCOUNT</span> <span style="color:Blue;">ON</span>
|
||||
<span style="color:Blue;">SELECT</span> @value = @value + 1
|
||||
<span style="color:Blue;">SET</span> <span style="color:Blue;">NOCOUNT</span> <span style="color:Blue;">OFF</span>
|
||||
<span style="color:Blue;">END</span>
|
||||
<span style="color:Blue;">SET</span> <span style="color:Blue;">NOCOUNT</span> <span style="color:Blue;">OFF</span>
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @angle <span style="color:Blue;">float</span>
|
||||
<span style="color:Blue;">SET</span> @angle = 45.175643
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:#A31515;">'The SIN of the angle is: '</span> + <span style="color:Magenta;">CONVERT</span>(<span style="color:Blue;">varchar</span>,<span style="color:Magenta;">SIN</span>(@angle))
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">DECLARE</span> @myvalue <span style="color:Blue;">float</span>;
|
||||
<span style="color:Blue;">SET</span> @myvalue = 1.00;
|
||||
<span style="color:Blue;">WHILE</span> @myvalue < 10.00
|
||||
<span style="color:Blue;">BEGIN</span>
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">SQRT</span>(@myvalue);
|
||||
<span style="color:Blue;">SET</span> @myvalue = @myvalue + 1
|
||||
<span style="color:Blue;">END</span>;
|
||||
GO
|
||||
|
||||
<span style="color:Blue;">SELECT</span> <span style="color:Magenta;">TAN</span>(<span style="color:Magenta;">PI</span>()/2);
|
||||
</pre></div>
|
|
@ -1,122 +0,0 @@
|
|||
SELECT ABS(-1.0), ABS(0.0), ABS(1.0)
|
||||
|
||||
SET NOCOUNT OFF;
|
||||
DECLARE @angle float;
|
||||
SET @angle = -1.0;
|
||||
SELECT 'The ACOS of the angle is: ' + CONVERT(varchar, ACOS(@angle));
|
||||
|
||||
/* The first value will be -1.01. This fails because the value is
|
||||
outside the range.*/
|
||||
DECLARE @angle float
|
||||
SET @angle = -1.01
|
||||
SELECT 'The ASIN of the angle is: ' + CONVERT(varchar, ASIN(@angle))
|
||||
GO
|
||||
|
||||
-- The next value is -1.00.
|
||||
DECLARE @angle float
|
||||
SET @angle = -1.00
|
||||
SELECT 'The ASIN of the angle is: ' + CONVERT(varchar, ASIN(@angle))
|
||||
GO
|
||||
|
||||
-- The next value is 0.1472738.
|
||||
DECLARE @angle float
|
||||
SET @angle = 0.1472738
|
||||
SELECT 'The ASIN of the angle is: ' + CONVERT(varchar, ASIN(@angle))
|
||||
GO
|
||||
|
||||
SELECT 'The ATAN of -45.01 is: ' + CONVERT(varchar, ATAN(-45.01))
|
||||
SELECT 'The ATAN of -181.01 is: ' + CONVERT(varchar, ATAN(-181.01))
|
||||
SELECT 'The ATAN of 0 is: ' + CONVERT(varchar, ATAN(0))
|
||||
SELECT 'The ATAN of 0.1472738 is: ' + CONVERT(varchar, ATAN(0.1472738))
|
||||
SELECT 'The ATAN of 197.1099392 is: ' + CONVERT(varchar, ATAN(197.1099392))
|
||||
GO
|
||||
|
||||
DECLARE @x float
|
||||
DECLARE @y float
|
||||
SET @x = 35.175643
|
||||
SET @y = 129.44
|
||||
SELECT 'The ATN2 of the angle is: ' + CONVERT(varchar,ATN2(@x,@y ))
|
||||
GO
|
||||
|
||||
SELECT CEILING($123.45), CEILING($-123.45), CEILING($0.0)
|
||||
GO
|
||||
|
||||
DECLARE @angle float
|
||||
SET @angle = 14.78
|
||||
SELECT 'The COS of the angle is: ' + CONVERT(varchar,COS(@angle))
|
||||
GO
|
||||
|
||||
DECLARE @angle float
|
||||
SET @angle = 124.1332
|
||||
SELECT 'The COT of the angle is: ' + CONVERT(varchar,COT(@angle))
|
||||
GO
|
||||
|
||||
SELECT 'The number of degrees in PI/2 radians is: ' +
|
||||
CONVERT(varchar, DEGREES((PI()/2)));
|
||||
GO
|
||||
|
||||
DECLARE @var float
|
||||
SET @var = 10
|
||||
SELECT 'The EXP of the variable is: ' + CONVERT(varchar,EXP(@var))
|
||||
GO
|
||||
|
||||
SELECT FLOOR(123.45), FLOOR(-123.45), FLOOR($123.45)
|
||||
|
||||
DECLARE @var float
|
||||
SET @var = 10
|
||||
SELECT 'The LOG of the variable is: ' + CONVERT(varchar, LOG(@var))
|
||||
GO
|
||||
|
||||
DECLARE @var float
|
||||
SET @var = 145.175643
|
||||
SELECT 'The LOG10 of the variable is: ' + CONVERT(varchar,LOG10(@var))
|
||||
GO
|
||||
|
||||
SELECT PI()
|
||||
GO
|
||||
|
||||
SELECT POWER(2.0, -100.0)
|
||||
GO
|
||||
|
||||
SELECT RADIANS(1e-307)
|
||||
GO
|
||||
|
||||
DECLARE @counter smallint
|
||||
SET @counter = 1
|
||||
WHILE @counter < 5
|
||||
BEGIN
|
||||
SELECT RAND() Random_Number
|
||||
SET @counter = @counter + 1
|
||||
END
|
||||
GO
|
||||
|
||||
SELECT ROUND(123.9994, 3), ROUND(123.9995, 3)
|
||||
GO
|
||||
|
||||
DECLARE @value real
|
||||
SET @value = -1
|
||||
WHILE @value < 2
|
||||
BEGIN
|
||||
SELECT SIGN(@value)
|
||||
SET NOCOUNT ON
|
||||
SELECT @value = @value + 1
|
||||
SET NOCOUNT OFF
|
||||
END
|
||||
SET NOCOUNT OFF
|
||||
GO
|
||||
|
||||
DECLARE @angle float
|
||||
SET @angle = 45.175643
|
||||
SELECT 'The SIN of the angle is: ' + CONVERT(varchar,SIN(@angle))
|
||||
GO
|
||||
|
||||
DECLARE @myvalue float;
|
||||
SET @myvalue = 1.00;
|
||||
WHILE @myvalue < 10.00
|
||||
BEGIN
|
||||
SELECT SQRT(@myvalue);
|
||||
SET @myvalue = @myvalue + 1
|
||||
END;
|
||||
GO
|
||||
|
||||
SELECT TAN(PI()/2);
|
|
@ -1,110 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Magenta;">ABS</span>
|
||||
<span style="color:Magenta;">ACOS</span>
|
||||
<span style="color:Magenta;">ASCII</span>
|
||||
<span style="color:Magenta;">ASIN</span>
|
||||
<span style="color:Magenta;">ATAN</span>
|
||||
<span style="color:Magenta;">ATN2</span>
|
||||
<span style="color:Magenta;">APP_NAME</span>
|
||||
<span style="color:Magenta;">AVG</span>
|
||||
<span style="color:Magenta;">BINARY_CHECKSUM</span>
|
||||
<span style="color:Magenta;">CAST</span>
|
||||
<span style="color:Magenta;">CEILING</span>
|
||||
<span style="color:Magenta;">CHARINDEX</span>
|
||||
<span style="color:Magenta;">CHECKSUM</span>
|
||||
<span style="color:Magenta;">CONVERT</span>
|
||||
<span style="color:Magenta;">COS</span>
|
||||
<span style="color:Magenta;">COT</span>
|
||||
<span style="color:Magenta;">COALESCE</span>
|
||||
<span style="color:Magenta;">COLLATIONPROPERTY</span>
|
||||
<span style="color:Magenta;">COLUMNS_UPDATED</span>
|
||||
<span style="color:Magenta;">COUNT</span>
|
||||
<span style="color:Magenta;">COUNT_BIG</span>
|
||||
<span style="color:Magenta;">CURRENT_TIMESTAMP</span>
|
||||
<span style="color:Magenta;">CURRENT_USER</span>
|
||||
<span style="color:Magenta;">CURSOR_STATUS</span>
|
||||
<span style="color:Magenta;">DATALENGTH</span>
|
||||
<span style="color:Magenta;">DAY</span>
|
||||
<span style="color:Magenta;">DB_NAME</span>
|
||||
<span style="color:Magenta;">DB_ID</span>
|
||||
<span style="color:Magenta;">DEGREES</span>
|
||||
<span style="color:Magenta;">DIFFERENCE</span>
|
||||
<span style="color:Magenta;">@@ERROR</span>
|
||||
<span style="color:Magenta;">EXP</span>
|
||||
<span style="color:Magenta;">ERROR_LINE</span>
|
||||
<span style="color:Magenta;">ERROR_MESSAGE</span>
|
||||
<span style="color:Magenta;">ERROR_NUMBER</span>
|
||||
<span style="color:Magenta;">ERROR_PROCEDURE</span>
|
||||
<span style="color:Magenta;">ERROR_SEVERITY</span>
|
||||
<span style="color:Magenta;">ERROR_STATE</span>
|
||||
<span style="color:Magenta;">@@FETCH_STATUS</span>
|
||||
<span style="color:Magenta;">FLOOR</span>
|
||||
<span style="color:Magenta;">FORMATMESSAGE</span>
|
||||
<span style="color:Magenta;">GETANSINULL</span>
|
||||
<span style="color:Magenta;">GETDATE</span>
|
||||
<span style="color:Magenta;">GROUPING</span>
|
||||
<span style="color:Magenta;">HOST_ID</span>
|
||||
<span style="color:Magenta;">HOST_NAME</span>
|
||||
<span style="color:Magenta;">IDENT_CURRENT</span>
|
||||
<span style="color:Magenta;">IDENT_INCR</span>
|
||||
<span style="color:Magenta;">IDENT_SEED</span>
|
||||
<span style="color:Magenta;">@@IDENTITY</span>
|
||||
<span style="color:Magenta;">ISDATE</span>
|
||||
<span style="color:Magenta;">ISNULL</span>
|
||||
<span style="color:Magenta;">ISNUMERIC</span>
|
||||
<span style="color:Magenta;">LEN</span>
|
||||
<span style="color:Magenta;">LOG</span>
|
||||
<span style="color:Magenta;">LOG10</span>
|
||||
<span style="color:Magenta;">LOWER</span>
|
||||
<span style="color:Magenta;">LTRIM</span>
|
||||
<span style="color:Magenta;">MAX</span>
|
||||
<span style="color:Magenta;">MIN</span>
|
||||
<span style="color:Magenta;">MONTH</span>
|
||||
<span style="color:Magenta;">NEWID</span>
|
||||
<span style="color:Magenta;">NULLIF</span>
|
||||
<span style="color:Magenta;">PARSENAME</span>
|
||||
<span style="color:Magenta;">PATINDEX</span>
|
||||
<span style="color:Magenta;">PI</span>
|
||||
<span style="color:Magenta;">POWER</span>
|
||||
<span style="color:Magenta;">ORIGINAL_LOGIN</span>
|
||||
<span style="color:Magenta;">RADIANS</span>
|
||||
<span style="color:Magenta;">RAND</span>
|
||||
<span style="color:Magenta;">ROUND</span>
|
||||
<span style="color:Magenta;">@@ROWCOUNT</span>
|
||||
<span style="color:Magenta;">ROW_NUMBER</span>
|
||||
<span style="color:Magenta;">RTRIM</span>
|
||||
<span style="color:Magenta;">SCOPE_IDENTITY</span>
|
||||
<span style="color:Magenta;">SERVERPROPERTY</span>
|
||||
<span style="color:Magenta;">SESSIONPROPERTY</span>
|
||||
<span style="color:Magenta;">SESSION_USER</span>
|
||||
<span style="color:Magenta;">SIGN</span>
|
||||
<span style="color:Magenta;">SIN</span>
|
||||
<span style="color:Magenta;">SPACE</span>
|
||||
<span style="color:Magenta;">STATS_DATE</span>
|
||||
<span style="color:Magenta;">STDEV</span>
|
||||
<span style="color:Magenta;">STDEVP</span>
|
||||
<span style="color:Magenta;">SUSER_NAME</span>
|
||||
<span style="color:Magenta;">SQRT</span>
|
||||
<span style="color:Magenta;">SQL_VARIANT</span>
|
||||
<span style="color:Magenta;">SQL_VARIANT_PROPERTY</span>
|
||||
<span style="color:Magenta;">SUBSTRING</span>
|
||||
<span style="color:Magenta;">SUM</span>
|
||||
<span style="color:Magenta;">SYSTEM_USER</span>
|
||||
<span style="color:Magenta;">TAN</span>
|
||||
<span style="color:Magenta;">@@TRANCOUNT</span>
|
||||
<span style="color:Magenta;">QUOTENAME</span>
|
||||
<span style="color:Magenta;">REPLACE</span>
|
||||
<span style="color:Magenta;">REPLICATE</span>
|
||||
<span style="color:Magenta;">REVERSE</span>
|
||||
<span style="color:Magenta;">SOUNDEX</span>
|
||||
<span style="color:Magenta;">STR</span>
|
||||
<span style="color:Magenta;">STUFF</span>
|
||||
<span style="color:Magenta;">UNICODE</span>
|
||||
<span style="color:Magenta;">UPPER</span>
|
||||
<span style="color:Magenta;">USER</span>
|
||||
<span style="color:Magenta;">USER_NAME</span>
|
||||
<span style="color:Magenta;">VAR</span>
|
||||
<span style="color:Magenta;">VARP</span>
|
||||
<span style="color:Magenta;">XACT_STATE</span>
|
||||
<span style="color:Magenta;">YEAR</span>
|
||||
</pre></div>
|
|
@ -1,108 +0,0 @@
|
|||
ABS
|
||||
ACOS
|
||||
ASCII
|
||||
ASIN
|
||||
ATAN
|
||||
ATN2
|
||||
APP_NAME
|
||||
AVG
|
||||
BINARY_CHECKSUM
|
||||
CAST
|
||||
CEILING
|
||||
CHARINDEX
|
||||
CHECKSUM
|
||||
CONVERT
|
||||
COS
|
||||
COT
|
||||
COALESCE
|
||||
COLLATIONPROPERTY
|
||||
COLUMNS_UPDATED
|
||||
COUNT
|
||||
COUNT_BIG
|
||||
CURRENT_TIMESTAMP
|
||||
CURRENT_USER
|
||||
CURSOR_STATUS
|
||||
DATALENGTH
|
||||
DAY
|
||||
DB_NAME
|
||||
DB_ID
|
||||
DEGREES
|
||||
DIFFERENCE
|
||||
@@ERROR
|
||||
EXP
|
||||
ERROR_LINE
|
||||
ERROR_MESSAGE
|
||||
ERROR_NUMBER
|
||||
ERROR_PROCEDURE
|
||||
ERROR_SEVERITY
|
||||
ERROR_STATE
|
||||
@@FETCH_STATUS
|
||||
FLOOR
|
||||
FORMATMESSAGE
|
||||
GETANSINULL
|
||||
GETDATE
|
||||
GROUPING
|
||||
HOST_ID
|
||||
HOST_NAME
|
||||
IDENT_CURRENT
|
||||
IDENT_INCR
|
||||
IDENT_SEED
|
||||
@@IDENTITY
|
||||
ISDATE
|
||||
ISNULL
|
||||
ISNUMERIC
|
||||
LEN
|
||||
LOG
|
||||
LOG10
|
||||
LOWER
|
||||
LTRIM
|
||||
MAX
|
||||
MIN
|
||||
MONTH
|
||||
NEWID
|
||||
NULLIF
|
||||
PARSENAME
|
||||
PATINDEX
|
||||
PI
|
||||
POWER
|
||||
ORIGINAL_LOGIN
|
||||
RADIANS
|
||||
RAND
|
||||
ROUND
|
||||
@@ROWCOUNT
|
||||
ROW_NUMBER
|
||||
RTRIM
|
||||
SCOPE_IDENTITY
|
||||
SERVERPROPERTY
|
||||
SESSIONPROPERTY
|
||||
SESSION_USER
|
||||
SIGN
|
||||
SIN
|
||||
SPACE
|
||||
STATS_DATE
|
||||
STDEV
|
||||
STDEVP
|
||||
SUSER_NAME
|
||||
SQRT
|
||||
SQL_VARIANT
|
||||
SQL_VARIANT_PROPERTY
|
||||
SUBSTRING
|
||||
SUM
|
||||
SYSTEM_USER
|
||||
TAN
|
||||
@@TRANCOUNT
|
||||
QUOTENAME
|
||||
REPLACE
|
||||
REPLICATE
|
||||
REVERSE
|
||||
SOUNDEX
|
||||
STR
|
||||
STUFF
|
||||
UNICODE
|
||||
UPPER
|
||||
USER
|
||||
USER_NAME
|
||||
VAR
|
||||
VARP
|
||||
XACT_STATE
|
||||
YEAR
|
|
@ -1,21 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">Public</span> <span style="color:Blue;">Class</span> LinqTest
|
||||
<span style="color:Blue;">Public</span> <span style="color:Blue;">Sub</span> DoSomething()
|
||||
|
||||
<span style="color:Blue;">Dim</span> test = <span style="color:Blue;">From</span> d <span style="color:Blue;">In</span> data
|
||||
<span style="color:Blue;">Aggregate</span> d <span style="color:Blue;">In</span> data <span style="color:Blue;">Into</span> data2 = <span style="color:Blue;">All</span>(<span style="color:Blue;">True</span>), data3 = <span style="color:Blue;">Any</span>(<span style="color:Blue;">True</span>), _
|
||||
data4 = <span style="color:Blue;">Average</span>(10), data5 = <span style="color:Blue;">Count</span>(<span style="color:Blue;">True</span>), data6 = <span style="color:Blue;">LongCount</span>(<span style="color:Blue;">True</span>), _
|
||||
data7 = <span style="color:Blue;">Max</span>(10), data8 = <span style="color:Blue;">Min</span>(10), data9 = <span style="color:Blue;">Sum</span>(10)
|
||||
<span style="color:Blue;">Join</span> d2 <span style="color:Blue;">In</span> data <span style="color:Blue;">On</span> d.Key <span style="color:Blue;">Equals</span> d2.Key
|
||||
<span style="color:Blue;">Group</span> <span style="color:Blue;">Join</span> g <span style="color:Blue;">In</span> data <span style="color:Blue;">On</span> d.Key <span style="color:Blue;">Equals</span> g2.Key
|
||||
<span style="color:Blue;">Group</span> <span style="color:Blue;">By</span> h = d.Key
|
||||
<span style="color:Blue;">Skip</span> 10 <span style="color:Blue;">Take</span> 10
|
||||
<span style="color:Blue;">Skip</span> <span style="color:Blue;">While</span> <span style="color:Blue;">True</span>
|
||||
<span style="color:Blue;">Take</span> <span style="color:Blue;">While</span> <span style="color:Blue;">True</span>
|
||||
<span style="color:Blue;">Order</span> <span style="color:Blue;">By</span> h.Key <span style="color:Blue;">Ascending</span>, h.Key <span style="color:Blue;">Descending</span>
|
||||
<span style="color:Blue;">Let</span> w = g.Key
|
||||
<span style="color:Blue;">Where</span> g.Key == <span style="color:#A31515;">"abc"</span>
|
||||
<span style="color:Blue;">Select</span> g <span style="color:Blue;">Distinct</span>
|
||||
<span style="color:Blue;">End</span> <span style="color:Blue;">Sub</span>
|
||||
<span style="color:Blue;">End</span> <span style="color:Blue;">Class</span>
|
||||
</pre></div>
|
|
@ -1,19 +0,0 @@
|
|||
Public Class LinqTest
|
||||
Public Sub DoSomething()
|
||||
|
||||
Dim test = From d In data
|
||||
Aggregate d In data Into data2 = All(True), data3 = Any(True), _
|
||||
data4 = Average(10), data5 = Count(True), data6 = LongCount(True), _
|
||||
data7 = Max(10), data8 = Min(10), data9 = Sum(10)
|
||||
Join d2 In data On d.Key Equals d2.Key
|
||||
Group Join g In data On d.Key Equals g2.Key
|
||||
Group By h = d.Key
|
||||
Skip 10 Take 10
|
||||
Skip While True
|
||||
Take While True
|
||||
Order By h.Key Ascending, h.Key Descending
|
||||
Let w = g.Key
|
||||
Where g.Key == "abc"
|
||||
Select g Distinct
|
||||
End Sub
|
||||
End Class
|
|
@ -1,11 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;">Public</span> <span style="color:Blue;">Class</span> StringsTest
|
||||
<span style="color:Blue;">Public</span> <span style="color:Blue;">Sub</span> DoSomething()
|
||||
<span style="color:Blue;">Dim</span> a <span style="color:Blue;">As</span> <span style="color:Blue;">String</span> = <span style="color:#A31515;">"someText"</span>
|
||||
<span style="color:Blue;">Dim</span> b <span style="color:Blue;">As</span> <span style="color:Blue;">String</span> = <span style="color:#A31515;">"""someText"""</span>
|
||||
<span style="color:Blue;">Dim</span> c <span style="color:Blue;">As</span> <span style="color:Blue;">String</span> = <span style="color:#A31515;">"foo ""someText"" foo"</span>
|
||||
<span style="color:Blue;">Dim</span> d <span style="color:Blue;">As</span> <span style="color:Blue;">String</span> = <span style="color:#A31515;">""</span>
|
||||
<span style="color:Blue;">Dim</span> e <span style="color:Blue;">As</span> <span style="color:Blue;">String</span> = <span style="color:#A31515;">"foo "</span> & <span style="color:#A31515;">"bar"</span>
|
||||
<span style="color:Blue;">End</span> <span style="color:Blue;">Sub</span>
|
||||
<span style="color:Blue;">End</span> <span style="color:Blue;">Class</span>
|
||||
</pre></div>
|
|
@ -1,9 +0,0 @@
|
|||
Public Class StringsTest
|
||||
Public Sub DoSomething()
|
||||
Dim a As String = "someText"
|
||||
Dim b As String = """someText"""
|
||||
Dim c As String = "foo ""someText"" foo"
|
||||
Dim d As String = ""
|
||||
Dim e As String = "foo " & "bar"
|
||||
End Sub
|
||||
End Class
|
|
@ -1,5 +0,0 @@
|
|||
<div style="color:Black;background-color:White;"><pre>
|
||||
<span style="color:Blue;"><?</span><span style="color:#A31515;">xml</span> <span style="color:Red;">version</span><span style="color:Blue;">=</span><span style="color:Black;">"</span><span style="color:Blue;">1.0</span><span style="color:Black;">"</span> <span style="color:Red;">encoding</span><span style="color:Blue;">=</span><span style="color:Black;">"</span><span style="color:Blue;">utf-8</span><span style="color:Black;">"</span> <span style="color:Blue;">?></span>
|
||||
<span style="color:Blue;"><?</span><span style="color:#A31515;">xml-stylesheet</span><span style="color:Gray;"> type="text/xsl" href="show_book.xsl" title="default stylesheet"</span><span style="color:Blue;">?></span>
|
||||
<span style="color:Blue;"><</span><span style="color:#A31515;">doc</span><span style="color:Blue;">></span><span style="color:Blue;"></</span><span style="color:#A31515;">doc</span><span style="color:Blue;">></span>
|
||||
</pre></div>
|
|
@ -1,3 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml-stylesheet type="text/xsl" href="show_book.xsl" title="default stylesheet"?>
|
||||
<doc></doc>
|
|
@ -1,183 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class JavaAcceptanceTests
|
||||
{
|
||||
public class CommentTests
|
||||
{
|
||||
[Fact]
|
||||
public void WillColorizeACommentOnMultipleLines()
|
||||
{
|
||||
const string source = @"/*
|
||||
comment line
|
||||
comment line 2
|
||||
*/";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">/*
|
||||
comment line
|
||||
comment line 2
|
||||
*/</span>");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillColorizeAMultieLineStyleCommentOnOneLine()
|
||||
{
|
||||
const string source = @"/*comment*/";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">/*comment*/</span>");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillColorizeASingleLineStyleComment()
|
||||
{
|
||||
const string source = @"//comment";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">//comment</span>");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public class StringTests
|
||||
{
|
||||
[Fact]
|
||||
public void WillColorizeStrings()
|
||||
{
|
||||
const string source = @"string aString = ""aString"";";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"string aString = <span style=""color:#A31515;"">"aString"</span>;");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillColorizeCharacters()
|
||||
{
|
||||
const string source = @"char aChar = 'a';";
|
||||
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Blue;"">char</span> aChar = <span style=""color:#A31515;"">'a'</span>;");
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public class KeywordTests
|
||||
{
|
||||
[Theory]
|
||||
[JavaKeywordData]
|
||||
public void WillColorizeAKeywordWithNoSurroundingText(string keyword)
|
||||
{
|
||||
var source = keyword;
|
||||
var exepected = AcceptanceHelper.BuildExpected(@"<span style=""color:Blue;"">{0}</span>", keyword);
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(exepected, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[JavaKeywordData]
|
||||
public void WillColorizeAKeywordWithPrecedingAndSucceedingText(string keyword)
|
||||
{
|
||||
var source = string.Format("fnord {0} fnord", keyword);
|
||||
var exepected = AcceptanceHelper.BuildExpected(@"fnord <span style=""color:Blue;"">{0}</span> fnord", keyword);
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(exepected, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[JavaKeywordData]
|
||||
public void WillNotColorizeAKeywordInsideAWord(string keyword)
|
||||
{
|
||||
var source = string.Format("fnord{0}fnord", keyword);
|
||||
var exepected = AcceptanceHelper.BuildExpected(@"fnord{0}fnord", keyword);
|
||||
|
||||
var actual = new CodeColorizer().Colorize(source, Languages.Java);
|
||||
|
||||
Assert.Equal(exepected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Theory Data
|
||||
public class JavaKeywordData : DataAttribute
|
||||
{
|
||||
public override IEnumerable<object[]> GetData(MethodInfo methodUnderTest, Type[] parameterTypes)
|
||||
{
|
||||
var keywordData = new List<object[]>
|
||||
{
|
||||
new object[] {"abstract"},
|
||||
new object[] {"assert"},
|
||||
new object[] {"boolean"},
|
||||
new object[] {"break"},
|
||||
new object[] {"byte"},
|
||||
new object[] {"case"},
|
||||
new object[] {"catch"},
|
||||
new object[] {"char"},
|
||||
new object[] {"class"},
|
||||
new object[] {"const"},
|
||||
new object[] {"continue"},
|
||||
new object[] {"default"},
|
||||
new object[] {"do"},
|
||||
new object[] {"double"},
|
||||
new object[] {"else"},
|
||||
new object[] {"enum"},
|
||||
new object[] {"extends"},
|
||||
new object[] {"false"},
|
||||
new object[] {"final"},
|
||||
new object[] {"finally"},
|
||||
new object[] {"float"},
|
||||
new object[] {"for"},
|
||||
new object[] {"goto"},
|
||||
new object[] {"if"},
|
||||
new object[] {"implements"},
|
||||
new object[] {"import"},
|
||||
new object[] {"instanceof"},
|
||||
new object[] {"int"},
|
||||
new object[] {"interface"},
|
||||
new object[] {"long"},
|
||||
new object[] {"native"},
|
||||
new object[] {"new"},
|
||||
new object[] {"null"},
|
||||
new object[] {"package"},
|
||||
new object[] {"private"},
|
||||
new object[] {"protected"},
|
||||
new object[] {"public"},
|
||||
new object[] {"return"},
|
||||
new object[] {"short"},
|
||||
new object[] {"static"},
|
||||
new object[] {"strictfp"},
|
||||
new object[] {"super"},
|
||||
new object[] {"switch"},
|
||||
new object[] {"synchronized"},
|
||||
new object[] {"this"},
|
||||
new object[] {"throw"},
|
||||
new object[] {"throws"},
|
||||
new object[] {"transient"},
|
||||
new object[] {"true"},
|
||||
new object[] {"try"},
|
||||
new object[] {"void"},
|
||||
new object[] {"volatile"},
|
||||
new object[] {"while"}
|
||||
};
|
||||
return keywordData;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.LegacyAcceptanceTests
|
||||
{
|
||||
public class AsaxAcceptanceTests
|
||||
{
|
||||
static ILanguage GetGrammar()
|
||||
{
|
||||
return Languages.Asax;
|
||||
}
|
||||
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillNotStyleKeyword()
|
||||
{
|
||||
string source = "get bool false";
|
||||
string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\nget bool false\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleHeaderWithKeywords()
|
||||
{
|
||||
string source = @"<%@ Application Language=""C#"" CodeBehind=""Global.asax.cs"" Inherits=""Microsoft.Foundation.Web.Global"" %><script runat=""server"">bool public false</script>";
|
||||
string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"background-color:Yellow;\"><%</span><span style=\"color:Blue;\">@</span> <span style=\"color:#A31515;\">Application</span> <span style=\"color:Red;\">Language</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"C#"</span> <span style=\"color:Red;\">CodeBehind</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"Global.asax.cs"</span> <span style=\"color:Red;\">Inherits</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"Microsoft.Foundation.Web.Global"</span> <span style=\"background-color:Yellow;\">%></span><span style=\"color:Blue;\"><</span><span style=\"color:#A31515;\">script</span> <span style=\"color:Red;\">runat</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"server"</span><span style=\"color:Blue;\">></span><span style=\"color:Blue;\">bool</span> <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">false</span><span style=\"color:Blue;\"></</span><span style=\"color:#A31515;\">script</span><span style=\"color:Blue;\">></span>\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.LegacyAcceptanceTests
|
||||
{
|
||||
public class AshxAcceptanceTests
|
||||
{
|
||||
static ILanguage GetGrammar()
|
||||
{
|
||||
return Languages.Ashx;
|
||||
}
|
||||
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillNotStyleKeyword()
|
||||
{
|
||||
string source = "get bool false";
|
||||
string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\nget bool false\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleHeader()
|
||||
{
|
||||
string source = @"<%@ Webhandler Language=""C#"" CodeBehind=""Global.asax.cs"" Inherits=""Microsoft.Foundation.Web.Global"" %>bool public false";
|
||||
string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"background-color:Yellow;\"><%</span><span style=\"color:Blue;\">@</span> <span style=\"color:#A31515;\">Webhandler</span> <span style=\"color:Red;\">Language</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"C#"</span> <span style=\"color:Red;\">CodeBehind</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"Global.asax.cs"</span> <span style=\"color:Red;\">Inherits</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"Microsoft.Foundation.Web.Global"</span> <span style=\"background-color:Yellow;\">%></span><span style=\"color:Blue;\">bool</span> <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">false</span>\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleClass()
|
||||
{
|
||||
string source =
|
||||
@"<%@ Webhandler Language=""C#"" CodeBehind=""Global.asax.cs"" Inherits=""Microsoft.Foundation.Web.Global"" %>
|
||||
<script runat=""server"">
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using CodePlex.Common;
|
||||
using CodePlex.Presentation.Compression;
|
||||
using CodePlex.Presentation.Css.Presenter;
|
||||
using CodePlex.Presentation.Navigation;
|
||||
|
||||
namespace CodePlex.WebSite.Css
|
||||
{
|
||||
/// <summary>
|
||||
/// StyleSheet.ashx parses and delivers css files submitted through the QueryString
|
||||
/// It replaces constants described by the css file in the form
|
||||
///
|
||||
/// /*{css:ConstantName}*/
|
||||
///
|
||||
/// with the correspondingly named AppSetting Key from the containing directory's .config file
|
||||
/// </summary>
|
||||
public class StyleSheet : IHttpHandler
|
||||
{
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = ""text/css"";
|
||||
if (context.Request.QueryString[""i""] == null)
|
||||
return;
|
||||
|
||||
string[] cssFiles;
|
||||
cssFiles = css.ToString().Split(',');
|
||||
for (int i = 0; i < cssFiles.Length; i++)
|
||||
{
|
||||
cssFiles[i] = Path.GetFileName(cssFiles[i].Trim());
|
||||
if (!Path.HasExtension(cssFiles[i]))
|
||||
cssFiles[i] = Path.ChangeExtension(cssFiles[i], "".css"");
|
||||
}
|
||||
|
||||
//Cache settings handled in AddHeaderItemsToRequestModule
|
||||
//bool alreadyCached;
|
||||
//CompressionUtility.SetCaching(context, cssFiles, out alreadyCached);
|
||||
//if (alreadyCached)
|
||||
// return;
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>";
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"background-color:Yellow;\"><%</span><span style=\"color:Blue;\">@</span> <span style=\"color:#A31515;\">Webhandler</span> <span style=\"color:Red;\">Language</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"C#"</span> <span style=\"color:Red;\">CodeBehind</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"Global.asax.cs"</span> <span style=\"color:Red;\">Inherits</span><span style=\"color:Blue;\">=</span><span style=\"color:Blue;\">"Microsoft.Foundation.Web.Global"</span> <span style=\"background-color:Yellow;\">%></span>\r\n<script runat=<span style=\"color:#A31515;\">"server"</span>>\r\n<span style=\"color:Blue;\">using</span> System.IO;\r\n<span style=\"color:Blue;\">using</span> System.Text;\r\n<span style=\"color:Blue;\">using</span> System.Web;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Common;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Presentation.Compression;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Presentation.Css.Presenter;\r\n<span style=\"color:Blue;\">using</span> CodePlex.Presentation.Navigation;\r\n\r\n<span style=\"color:Blue;\">namespace</span> CodePlex.WebSite.Css\r\n{\r\n <span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"><summary></span>\r\n <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> StyleSheet.ashx parses and delivers css files submitted through the QueryString</span>\r\n <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> It replaces constants described by the css file in the form </span>\r\n <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> </span>\r\n <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> /*{css:ConstantName}*/</span>\r\n <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> </span>\r\n <span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> with the correspondingly named AppSetting Key from the containing directory's .config file</span>\r\n <span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"></summary></span>\r\n <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> StyleSheet : IHttpHandler\r\n {\r\n <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">void</span> ProcessRequest(HttpContext context)\r\n {\r\n context.Response.ContentType = <span style=\"color:#A31515;\">"text/css"</span>;\r\n <span style=\"color:Blue;\">if</span> (context.Request.QueryString[<span style=\"color:#A31515;\">"i"</span>] == <span style=\"color:Blue;\">null</span>)\r\n <span style=\"color:Blue;\">return</span>;\r\n\r\n <span style=\"color:Blue;\">string</span>[] cssFiles;\r\n cssFiles = css.ToString().Split(<span style=\"color:#A31515;\">','</span>);\r\n <span style=\"color:Blue;\">for</span> (<span style=\"color:Blue;\">int</span> i = 0; i < cssFiles.Length; i++)\r\n {\r\n cssFiles[i] = Path.GetFileName(cssFiles[i].Trim());\r\n <span style=\"color:Blue;\">if</span> (!Path.HasExtension(cssFiles[i]))\r\n cssFiles[i] = Path.ChangeExtension(cssFiles[i], <span style=\"color:#A31515;\">".css"</span>);\r\n }\r\n\r\n <span style=\"color:Green;\">//Cache settings handled in AddHeaderItemsToRequestModule</span>\r\n <span style=\"color:Green;\">//bool alreadyCached;</span>\r\n <span style=\"color:Green;\">//CompressionUtility.SetCaching(context, cssFiles, out alreadyCached);</span>\r\n <span style=\"color:Green;\">//if (alreadyCached)</span>\r\n <span style=\"color:Green;\">// return;</span>\r\n }\r\n\r\n <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">bool</span> IsReusable\r\n {\r\n <span style=\"color:Blue;\">get</span> { <span style=\"color:Blue;\">return</span> <span style=\"color:Blue;\">false</span>; }\r\n }\r\n }\r\n}\r\n</script>\r\n</pre></div>";
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.AspxAcceptanceTests
|
||||
{
|
||||
public class AspxScenarioTests
|
||||
{
|
||||
static ILanguage GetGrammar()
|
||||
{
|
||||
return Languages.Aspx;
|
||||
}
|
||||
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStylePageDeclaration()
|
||||
{
|
||||
string source =
|
||||
@"<%--
|
||||
DefaultStyleSheet skin template. The following skins are provided as examples only.
|
||||
|
||||
1. Named control skin. The SkinId should be uniquely defined because
|
||||
duplicate SkinId's per control type are not allowed in the same theme.
|
||||
|
||||
<asp:GridView runat=""server"" SkinId=""gridviewSkin"" BackColor=""White"" >
|
||||
<AlternatingRowStyle BackColor=""Blue"" />
|
||||
</asp:GridView>
|
||||
|
||||
2. DefaultStyleSheet skin. The SkinId is not defined. Only one default
|
||||
control skin per control type is allowed in the same theme.
|
||||
|
||||
<asp:Image runat=""server"" ImageUrl=""~/images/image1.jpg"" />
|
||||
--%>
|
||||
<asp:GridView runat=""server"" SkinId=""gridviewSkin"" BackColor=""White"" >
|
||||
<AlternatingRowStyle BackColor=""Blue"" />
|
||||
</asp:GridView>
|
||||
<asp:Image runat=""server"" ImageUrl=""~/images/image1.jpg"" />
|
||||
";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Green;"">--
|
||||
DefaultStyleSheet skin template. The following skins are provided as examples only.
|
||||
|
||||
1. Named control skin. The SkinId should be uniquely defined because
|
||||
duplicate SkinId's per control type are not allowed in the same theme.
|
||||
|
||||
<asp:GridView runat="server" SkinId="gridviewSkin" BackColor="White" >
|
||||
<AlternatingRowStyle BackColor="Blue" />
|
||||
</asp:GridView>
|
||||
|
||||
2. DefaultStyleSheet skin. The SkinId is not defined. Only one default
|
||||
control skin per control type is allowed in the same theme.
|
||||
|
||||
<asp:Image runat="server" ImageUrl="~/images/image1.jpg" />
|
||||
--</span><span style=""background-color:Yellow;"">%></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">GridView</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span> <span style=""color:Red;"">SkinId</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"gridviewSkin"</span> <span style=""color:Red;"">BackColor</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"White"</span> <span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">AlternatingRowStyle</span> <span style=""color:Red;"">BackColor</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"Blue"</span> <span style=""color:Blue;"">/></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">GridView</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">Image</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span> <span style=""color:Red;"">ImageUrl</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"~/images/image1.jpg"</span> <span style=""color:Blue;"">/></span>
|
||||
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleElementsWithNamespace()
|
||||
{
|
||||
string source =
|
||||
@"<asp:DropDownList ID=""StateList"" runat=""server"">
|
||||
<asp:ListItem>CA</asp:ListItem>
|
||||
<asp:ListItem>IN</asp:ListItem>
|
||||
<asp:ListItem>KS</asp:ListItem>
|
||||
<asp:ListItem>MD</asp:ListItem>
|
||||
<asp:ListItem>MI</asp:ListItem>
|
||||
<asp:ListItem>OR</asp:ListItem>
|
||||
<asp:ListItem>TN</asp:ListItem>
|
||||
<asp:ListItem>UT</asp:ListItem>
|
||||
</asp:DropDownList>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"StateList"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>CA<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>IN<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>KS<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>MD<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>MI<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>OR<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>TN<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>UT<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDoctypeWithLineBreakInDoubleQuotedString()
|
||||
{
|
||||
string source =
|
||||
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML
|
||||
1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">html</span> <span style=""color:Red;"">PUBLIC</span> <span style=""color:Blue;"">"-//W3C//DTD XHTML
|
||||
1.1//EN"</span> <span style=""color:Blue;"">"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,177 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.AspxCsAcceptanceTests
|
||||
{
|
||||
public class AspxCsScenarioTests
|
||||
{
|
||||
static ILanguage GetGrammar()
|
||||
{
|
||||
return Languages.AspxCs;
|
||||
}
|
||||
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStylePageDeclaration()
|
||||
{
|
||||
string source =
|
||||
@"<%@ Page LanguageDefinition=""C#"" AutoEventWireup=""true"" CodeBehind=""DefaultStyleSheet.aspx.cs"" Inherits=""WebApplication2._Default"" %>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Blue;"">@</span> <span style=""color:#A31515;"">Page</span> <span style=""color:Red;"">LanguageDefinition</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"C#"</span> <span style=""color:Red;"">AutoEventWireup</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"true"</span> <span style=""color:Red;"">CodeBehind</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"DefaultStyleSheet.aspx.cs"</span> <span style=""color:Red;"">Inherits</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"WebApplication2._Default"</span> <span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmbeddedCs()
|
||||
{
|
||||
string source =
|
||||
@"<%
|
||||
public string Foo()
|
||||
{
|
||||
return ""foo"";
|
||||
}
|
||||
%>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span>
|
||||
<span style=""color:Blue;"">public</span> <span style=""color:Blue;"">string</span> Foo()
|
||||
{
|
||||
<span style=""color:Blue;"">return</span> <span style=""color:#A31515;"">"foo"</span>;
|
||||
}
|
||||
<span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmbeddedWrite()
|
||||
{
|
||||
string source =
|
||||
@"<%=String.Format(""Foo{0}"", ""Bar"")%>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%=</span>String.Format(<span style=""color:#A31515;"">"Foo{0}"</span>, <span style=""color:#A31515;"">"Bar"</span>)<span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleServerSideComment()
|
||||
{
|
||||
string source =
|
||||
@"<%--
|
||||
String.Format(""Foo{0}"", ""Bar"")
|
||||
--%>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Green;"">--
|
||||
String.Format("Foo{0}", "Bar")
|
||||
--</span><span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleElementsWithNamespace()
|
||||
{
|
||||
string source =
|
||||
@"<asp:DropDownList ID=""StateList"" runat=""server"">
|
||||
<asp:ListItem>CA</asp:ListItem>
|
||||
<asp:ListItem>IN</asp:ListItem>
|
||||
<asp:ListItem>KS</asp:ListItem>
|
||||
<asp:ListItem>MD</asp:ListItem>
|
||||
<asp:ListItem>MI</asp:ListItem>
|
||||
<asp:ListItem>OR</asp:ListItem>
|
||||
<asp:ListItem>TN</asp:ListItem>
|
||||
<asp:ListItem>UT</asp:ListItem>
|
||||
</asp:DropDownList>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"StateList"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>CA<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>IN<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>KS<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>MD<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>MI<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>OR<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>TN<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>UT<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleElementsWithNamespaceAndEmbeddedCode()
|
||||
{
|
||||
string source =
|
||||
@"<asp:DataList ID=""MyList"" runat=""server"">
|
||||
<ItemTemplate>
|
||||
<%# string.Format(""Here is the value: {0}"", theValue) %>
|
||||
</ItemTemplate>
|
||||
</asp:DataList>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DataList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"MyList"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">ItemTemplate</span><span style=""color:Blue;"">></span>
|
||||
<span style=""background-color:Yellow;""><%</span># <span style=""color:Blue;"">string</span>.Format(<span style=""color:#A31515;"">"Here is the value: {0}"</span>, theValue) <span style=""background-color:Yellow;"">%></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">ItemTemplate</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DataList</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDoctypeWithLineBreakInDoubleQuotedString()
|
||||
{
|
||||
string source =
|
||||
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML
|
||||
1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">html</span> <span style=""color:Red;"">PUBLIC</span> <span style=""color:Blue;"">"-//W3C//DTD XHTML
|
||||
1.1//EN"</span> <span style=""color:Blue;"">"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleServerDeclarationWithSpaceAroundAttributeEqualSign()
|
||||
{
|
||||
string source =
|
||||
@"<%@ Assembly StyleName = ""assemblyname"" src=""pathname"" %>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Blue;"">@</span> <span style=""color:#A31515;"">Assembly</span> <span style=""color:Red;"">StyleName</span> <span style=""color:Blue;"">=</span> <span style=""color:Blue;"">"assemblyname"</span> <span style=""color:Red;"">src</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"pathname"</span> <span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,228 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.AspxVbAcceptanceTests
|
||||
{
|
||||
public class AspxVbScenarioTests
|
||||
{
|
||||
static ILanguage GetGrammar()
|
||||
{
|
||||
return Languages.AspxVb;
|
||||
}
|
||||
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStylePageDeclaration()
|
||||
{
|
||||
string source =
|
||||
@"<%@ Page LanguageDefinition=""VB"" AutoEventWireup=""false"" CodeFile=""DefaultStyleSheet.aspx.vb"" Inherits=""_Default"" %>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Blue;"">@</span> <span style=""color:#A31515;"">Page</span> <span style=""color:Red;"">LanguageDefinition</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"VB"</span> <span style=""color:Red;"">AutoEventWireup</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"false"</span> <span style=""color:Red;"">CodeFile</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"DefaultStyleSheet.aspx.vb"</span> <span style=""color:Red;"">Inherits</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"_Default"</span> <span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmbeddedVb()
|
||||
{
|
||||
string source =
|
||||
@"<%
|
||||
Public Sub WriteFoo()
|
||||
Response.Write(""Foo"")
|
||||
End Sub
|
||||
%>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span>
|
||||
<span style=""color:Blue;"">Public</span> <span style=""color:Blue;"">Sub</span> WriteFoo()
|
||||
Response.Write(<span style=""color:#A31515;"">"Foo"</span>)
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
<span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmbeddedWrite()
|
||||
{
|
||||
string source =
|
||||
@"<%=String.Format(""Foo{0}"", ""Bar"")%>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%=</span><span style=""color:Blue;"">String</span>.Format(<span style=""color:#A31515;"">"Foo{0}"</span>, <span style=""color:#A31515;"">"Bar"</span>)<span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleVbEmbeddedInScriptRunatServer()
|
||||
{
|
||||
string source =
|
||||
@"<script runat=""server"">
|
||||
Public Sub WriteFoo()
|
||||
Response.Write(""Foo"")
|
||||
End Sub
|
||||
</script>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">script</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;"">Public</span> <span style=""color:Blue;"">Sub</span> WriteFoo()
|
||||
Response.Write(<span style=""color:#A31515;"">"Foo"</span>)
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">script</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleServerSideComment()
|
||||
{
|
||||
string source =
|
||||
@"<%--
|
||||
String.Format(""Foo{0}"", ""Bar"")
|
||||
--%>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Green;"">--
|
||||
String.Format("Foo{0}", "Bar")
|
||||
--</span><span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmbeddedDataBindInSingleQuotes()
|
||||
{
|
||||
string source =
|
||||
@"<asp:LinkButton id=""LinkButton1"" runat=""Server"" CommandName=""Delete"" CommandArgument='<%# DataBinder.Eval(Container.DataItem,""ID"") %>'>x</asp:LinkButton>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">LinkButton</span> <span style=""color:Red;"">id</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"LinkButton1"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"Server"</span> <span style=""color:Red;"">CommandName</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"Delete"</span> <span style=""color:Red;"">CommandArgument</span><span style=""color:Blue;"">=</span>'<span style=""background-color:Yellow;""><%#</span> DataBinder.Eval(Container.DataItem,<span style=""color:#A31515;"">"ID"</span>) <span style=""background-color:Yellow;"">%></span>'<span style=""color:Blue;"">></span>x<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">LinkButton</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmbeddedDataBindInDoubleQuotes()
|
||||
{
|
||||
string source =
|
||||
@"<asp:LinkButton id=""LinkButton1"" runat=""Server"" CommandName=""Delete"" CommandArgument=""<%# DataBinder.Eval(Container.DataItem,""ID"") %>"">x</asp:LinkButton>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">LinkButton</span> <span style=""color:Red;"">id</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"LinkButton1"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"Server"</span> <span style=""color:Red;"">CommandName</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"Delete"</span> <span style=""color:Red;"">CommandArgument</span><span style=""color:Blue;"">=</span>"<span style=""background-color:Yellow;""><%#</span> DataBinder.Eval(Container.DataItem,<span style=""color:#A31515;"">"ID"</span>) <span style=""background-color:Yellow;"">%></span>"<span style=""color:Blue;"">></span>x<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">LinkButton</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleElementsWithNamespace()
|
||||
{
|
||||
string source =
|
||||
@"<asp:DropDownList ID=""StateList"" runat=""server"">
|
||||
<asp:ListItem>CA</asp:ListItem>
|
||||
<asp:ListItem>IN</asp:ListItem>
|
||||
<asp:ListItem>KS</asp:ListItem>
|
||||
<asp:ListItem>MD</asp:ListItem>
|
||||
<asp:ListItem>MI</asp:ListItem>
|
||||
<asp:ListItem>OR</asp:ListItem>
|
||||
<asp:ListItem>TN</asp:ListItem>
|
||||
<asp:ListItem>UT</asp:ListItem>
|
||||
</asp:DropDownList>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"StateList"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>CA<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>IN<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>KS<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>MD<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>MI<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>OR<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>TN<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>UT<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">ListItem</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DropDownList</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleElementsWithNamespaceAndEmbeddedCode()
|
||||
{
|
||||
string source =
|
||||
@"<asp:DataList ID=""MyList"" runat=""server"">
|
||||
<ItemTemplate>
|
||||
<%# String.Format(""Here is the value: {0}"", theValue) %>
|
||||
</ItemTemplate>
|
||||
</asp:DataList>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DataList</span> <span style=""color:Red;"">ID</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"MyList"</span> <span style=""color:Red;"">runat</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"server"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">ItemTemplate</span><span style=""color:Blue;"">></span>
|
||||
<span style=""background-color:Yellow;""><%</span># <span style=""color:Blue;"">String</span>.Format(<span style=""color:#A31515;"">"Here is the value: {0}"</span>, theValue) <span style=""background-color:Yellow;"">%></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">ItemTemplate</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">asp</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">DataList</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDoctypeWithLineBreakInDoubleQuotedString()
|
||||
{
|
||||
string source =
|
||||
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML
|
||||
1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">html</span> <span style=""color:Red;"">PUBLIC</span> <span style=""color:Blue;"">"-//W3C//DTD XHTML
|
||||
1.1//EN"</span> <span style=""color:Blue;"">"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleServerDeclarationWithSpaceAroundAttributeEqualSign()
|
||||
{
|
||||
string source =
|
||||
@"<%@ Assembly StyleName = ""assemblyname"" src=""pathname"" %>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""background-color:Yellow;""><%</span><span style=""color:Blue;"">@</span> <span style=""color:#A31515;"">Assembly</span> <span style=""color:Red;"">StyleName</span> <span style=""color:Blue;"">=</span> <span style=""color:Blue;"">"assemblyname"</span> <span style=""color:Red;"">src</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"pathname"</span> <span style=""background-color:Yellow;"">%></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, GetGrammar());
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -1,230 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.CSharpAcceptanceTests
|
||||
{
|
||||
public class CSharpKeywordTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleKnownKeywords()
|
||||
{
|
||||
string sourceText =
|
||||
@"#define
|
||||
#elif
|
||||
#else
|
||||
#endif
|
||||
#endregion
|
||||
#error
|
||||
#if
|
||||
#line
|
||||
#pragma
|
||||
#region
|
||||
#undef
|
||||
#warning
|
||||
abstract
|
||||
as
|
||||
base
|
||||
bool
|
||||
break
|
||||
byte
|
||||
case
|
||||
catch
|
||||
char
|
||||
checked
|
||||
const
|
||||
continue
|
||||
decimal
|
||||
default
|
||||
delegate
|
||||
do
|
||||
double
|
||||
else
|
||||
enum
|
||||
event
|
||||
explicit
|
||||
extern
|
||||
false
|
||||
finally
|
||||
fixed
|
||||
float
|
||||
for
|
||||
foreach
|
||||
goto
|
||||
if
|
||||
implicit
|
||||
in
|
||||
int
|
||||
internal
|
||||
is
|
||||
lock
|
||||
long
|
||||
namespace
|
||||
new
|
||||
null
|
||||
object
|
||||
operator
|
||||
out
|
||||
override
|
||||
params
|
||||
partial
|
||||
private
|
||||
protected
|
||||
public
|
||||
readonly
|
||||
ref
|
||||
return
|
||||
sbyte
|
||||
sealed
|
||||
short
|
||||
sizeof
|
||||
stackalloc
|
||||
static
|
||||
string
|
||||
struct
|
||||
switch
|
||||
this
|
||||
throw
|
||||
true
|
||||
try
|
||||
typeof
|
||||
uint
|
||||
ulong
|
||||
unchecked
|
||||
unsafe
|
||||
ushort
|
||||
using
|
||||
virtual
|
||||
void
|
||||
volatile
|
||||
while";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">#define</span>
|
||||
<span style=""color:Blue;"">#elif</span>
|
||||
<span style=""color:Blue;"">#else</span>
|
||||
<span style=""color:Blue;"">#endif</span>
|
||||
<span style=""color:Blue;"">#endregion</span>
|
||||
<span style=""color:Blue;"">#error</span>
|
||||
<span style=""color:Blue;"">#if</span>
|
||||
<span style=""color:Blue;"">#line</span>
|
||||
<span style=""color:Blue;"">#pragma</span>
|
||||
<span style=""color:Blue;"">#region</span>
|
||||
<span style=""color:Blue;"">#undef</span>
|
||||
<span style=""color:Blue;"">#warning</span>
|
||||
<span style=""color:Blue;"">abstract</span>
|
||||
<span style=""color:Blue;"">as</span>
|
||||
<span style=""color:Blue;"">base</span>
|
||||
<span style=""color:Blue;"">bool</span>
|
||||
<span style=""color:Blue;"">break</span>
|
||||
<span style=""color:Blue;"">byte</span>
|
||||
<span style=""color:Blue;"">case</span>
|
||||
<span style=""color:Blue;"">catch</span>
|
||||
<span style=""color:Blue;"">char</span>
|
||||
<span style=""color:Blue;"">checked</span>
|
||||
<span style=""color:Blue;"">const</span>
|
||||
<span style=""color:Blue;"">continue</span>
|
||||
<span style=""color:Blue;"">decimal</span>
|
||||
<span style=""color:Blue;"">default</span>
|
||||
<span style=""color:Blue;"">delegate</span>
|
||||
<span style=""color:Blue;"">do</span>
|
||||
<span style=""color:Blue;"">double</span>
|
||||
<span style=""color:Blue;"">else</span>
|
||||
<span style=""color:Blue;"">enum</span>
|
||||
<span style=""color:Blue;"">event</span>
|
||||
<span style=""color:Blue;"">explicit</span>
|
||||
<span style=""color:Blue;"">extern</span>
|
||||
<span style=""color:Blue;"">false</span>
|
||||
<span style=""color:Blue;"">finally</span>
|
||||
<span style=""color:Blue;"">fixed</span>
|
||||
<span style=""color:Blue;"">float</span>
|
||||
<span style=""color:Blue;"">for</span>
|
||||
<span style=""color:Blue;"">foreach</span>
|
||||
<span style=""color:Blue;"">goto</span>
|
||||
<span style=""color:Blue;"">if</span>
|
||||
<span style=""color:Blue;"">implicit</span>
|
||||
<span style=""color:Blue;"">in</span>
|
||||
<span style=""color:Blue;"">int</span>
|
||||
<span style=""color:Blue;"">internal</span>
|
||||
<span style=""color:Blue;"">is</span>
|
||||
<span style=""color:Blue;"">lock</span>
|
||||
<span style=""color:Blue;"">long</span>
|
||||
<span style=""color:Blue;"">namespace</span>
|
||||
<span style=""color:Blue;"">new</span>
|
||||
<span style=""color:Blue;"">null</span>
|
||||
<span style=""color:Blue;"">object</span>
|
||||
<span style=""color:Blue;"">operator</span>
|
||||
<span style=""color:Blue;"">out</span>
|
||||
<span style=""color:Blue;"">override</span>
|
||||
<span style=""color:Blue;"">params</span>
|
||||
<span style=""color:Blue;"">partial</span>
|
||||
<span style=""color:Blue;"">private</span>
|
||||
<span style=""color:Blue;"">protected</span>
|
||||
<span style=""color:Blue;"">public</span>
|
||||
<span style=""color:Blue;"">readonly</span>
|
||||
<span style=""color:Blue;"">ref</span>
|
||||
<span style=""color:Blue;"">return</span>
|
||||
<span style=""color:Blue;"">sbyte</span>
|
||||
<span style=""color:Blue;"">sealed</span>
|
||||
<span style=""color:Blue;"">short</span>
|
||||
<span style=""color:Blue;"">sizeof</span>
|
||||
<span style=""color:Blue;"">stackalloc</span>
|
||||
<span style=""color:Blue;"">static</span>
|
||||
<span style=""color:Blue;"">string</span>
|
||||
<span style=""color:Blue;"">struct</span>
|
||||
<span style=""color:Blue;"">switch</span>
|
||||
<span style=""color:Blue;"">this</span>
|
||||
<span style=""color:Blue;"">throw</span>
|
||||
<span style=""color:Blue;"">true</span>
|
||||
<span style=""color:Blue;"">try</span>
|
||||
<span style=""color:Blue;"">typeof</span>
|
||||
<span style=""color:Blue;"">uint</span>
|
||||
<span style=""color:Blue;"">ulong</span>
|
||||
<span style=""color:Blue;"">unchecked</span>
|
||||
<span style=""color:Blue;"">unsafe</span>
|
||||
<span style=""color:Blue;"">ushort</span>
|
||||
<span style=""color:Blue;"">using</span>
|
||||
<span style=""color:Blue;"">virtual</span>
|
||||
<span style=""color:Blue;"">void</span>
|
||||
<span style=""color:Blue;"">volatile</span>
|
||||
<span style=""color:Blue;"">while</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleKnownAttributeTargets()
|
||||
{
|
||||
string source =
|
||||
@"[assembly: SomeAttribute]
|
||||
[module: SomeAttribute]
|
||||
[type: SomeAttribute]
|
||||
[return: SomeAttribute]
|
||||
[param: SomeAttribute]
|
||||
[method: SomeAttribute]
|
||||
[field: SomeAttribute]
|
||||
[property: SomeAttribute]
|
||||
[event: SomeAttribute]";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
[<span style=""color:Blue;"">assembly</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">module</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">type</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">return</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">param</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">method</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">field</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">property</span>: SomeAttribute]
|
||||
[<span style=""color:Blue;"">event</span>: SomeAttribute]
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace ColorCode.CSharpAcceptanceTests
|
||||
{
|
||||
public class CSharpScenarioTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleDocComment()
|
||||
{
|
||||
string source =
|
||||
@"/// <summary>The</summary>";
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"><summary></span><span style=\"color:Green;\">The</summary></span>\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDocCommentMultilineWithSpaces()
|
||||
{
|
||||
string source =
|
||||
@"/// <exception cref=""CompositionException"">
|
||||
/// An error occurred during composition. <see cref=""CompositionException.Issues""/> will
|
||||
/// contain a list of errors that occurred.
|
||||
/// </exception>
|
||||
/// test
|
||||
";
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"><exception cref="CompositionException"></span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> An error occurred during composition. <see cref="CompositionException.Issues"/> will </span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> contain a list of errors that occurred.</span>\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"></exception></span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> test</span>\r\n\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDocCommentMultilineWithcref()
|
||||
{
|
||||
string source =
|
||||
@"using System;
|
||||
|
||||
/// <exception cref=""Class1"">
|
||||
/// An error occurred during composition. <see cref=""Class1.test""/> will
|
||||
/// contain a list of errors that occurred.
|
||||
/// </exception>
|
||||
/// test
|
||||
public class Class1
|
||||
{
|
||||
public void test()
|
||||
{
|
||||
}
|
||||
}";
|
||||
string expected = "<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Blue;\">using</span> System;\r\n\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"><exception cref="Class1"></span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> An error occurred during composition. <see cref="Class1.test"/> will </span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> contain a list of errors that occurred.</span>\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"></exception></span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> test</span>\r\n<span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> Class1\r\n{\r\n <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">void</span> test()\r\n\t{\r\n\t}\r\n}\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact(Skip = "")]
|
||||
public void WillStyleMultiLineComment()
|
||||
{
|
||||
string source =
|
||||
@"/// <summary>
|
||||
/// This class implements the MD4 message digest algorithm.";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;""><span style=""color:Gray;"">///</span></span><span style=""color:Green;""> </span><span style=""color:Blue;""><span style=""color:Gray;""><</span><span style=""color:Gray;"">summary</span></span><span style=""color:Blue;""><span style=""color:Gray;"">></span></span>
|
||||
<span style=""color:Green;""><span style=""color:Gray;"">///</span></span><span style=""color:Green;""> This class implements the MD4 message digest algorithm.</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleExceptionWithString()
|
||||
{
|
||||
string source = @"throw new InvalidOperationException(""GetDigest cannot be called twice for a single hash sequence. Call Reset() ."");";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">throw</span> <span style=""color:Blue;"">new</span> InvalidOperationException(<span style=""color:#A31515;"">"GetDigest cannot be called twice for a single hash sequence. Call Reset() ."</span>);
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleEmptySource()
|
||||
{
|
||||
string source = String.Empty;
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleASolitaryUsingStatement()
|
||||
{
|
||||
string source =
|
||||
@"using System;";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">using</span> System;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleTwoUsingStatements()
|
||||
{
|
||||
string source =
|
||||
@"using System;
|
||||
using Fnord;";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">using</span> System;
|
||||
<span style=""color:Blue;"">using</span> Fnord;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleAMethodWithoutArguments()
|
||||
{
|
||||
string source =
|
||||
@"using System;
|
||||
|
||||
namespace TheNamespace
|
||||
{
|
||||
/* This is a comment */
|
||||
public class TheClass
|
||||
: TheBaseClass, Implements
|
||||
{
|
||||
public string AMethod()
|
||||
{
|
||||
return ""Hello World!"";
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Blue;\">using</span> System;\r\n\r\n<span style=\"color:Blue;\">namespace</span> TheNamespace\r\n{\r\n <span style=\"color:Green;\">/* This is a comment */</span>\r\n <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> TheClass\r\n : TheBaseClass, Implements\r\n {\r\n <span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">string</span> AMethod()\r\n {\r\n <span style=\"color:Blue;\">return</span> <span style=\"color:#A31515;\">"Hello World!"</span>;\r\n }\r\n }\r\n}\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleBaseClassOnSameLineAsClass()
|
||||
{
|
||||
string source =
|
||||
@"public class TheClass : TheBaseClass
|
||||
{
|
||||
}";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">public</span> <span style=""color:Blue;"">class</span> TheClass : TheBaseClass
|
||||
{
|
||||
}
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleMultiLineStatement()
|
||||
{
|
||||
string source =
|
||||
@"/*
|
||||
Line 1
|
||||
Line 2
|
||||
Line 3
|
||||
*/";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">/*
|
||||
Line 1
|
||||
Line 2
|
||||
Line 3
|
||||
*/</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleThrowStatement()
|
||||
{
|
||||
string source =
|
||||
@"throw new InvalidOperationException();";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">throw</span> <span style=""color:Blue;"">new</span> InvalidOperationException();
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAttributeTarget()
|
||||
{
|
||||
string source =
|
||||
@"[assembly: SomeAttribute]";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
[<span style=""color:Blue;"">assembly</span>: SomeAttribute]
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleClassName()
|
||||
{
|
||||
string source =
|
||||
@"public class ClassName
|
||||
{";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">public</span> <span style=""color:Blue;"">class</span> ClassName
|
||||
{
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleMultipleDocComments()
|
||||
{
|
||||
string source =
|
||||
@"/// <summary>
|
||||
/// Contains various static methods that are used to verify that conditions are met during the
|
||||
/// process of running tests.
|
||||
/// </summary>
|
||||
public class Assert {";
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"><summary></span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> Contains various static methods that are used to verify that conditions are met during the</span>\r\n<span style=\"color:Gray;\">///</span><span style=\"color:Green;\"> process of running tests.</span>\r\n<span style=\"color:Gray;\">///</span> <span style=\"color:Gray;\"></summary></span>\r\n<span style=\"color:Blue;\">public</span> <span style=\"color:Blue;\">class</span> Assert {\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.CSharp);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,353 +0,0 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class HtmlAcceptanceTests
|
||||
{
|
||||
[Fact]
|
||||
public void TransformWillStyleASimpleElement()
|
||||
{
|
||||
string source =
|
||||
@"<html>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">html</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStylAnElementWithAttributes()
|
||||
{
|
||||
string source =
|
||||
@"<anElement anAttribute=""anAttributeValue"" />";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">anElement</span> <span style=""color:Red;"">anAttribute</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"anAttributeValue"</span> <span style=""color:Blue;"">/></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStylHeadAndTitleElements()
|
||||
{
|
||||
string source =
|
||||
@"<head>
|
||||
<title>The Web Site Title</title>
|
||||
</head>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">head</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">title</span><span style=""color:Blue;"">></span>The Web Site Title<span style=""color:Blue;""></</span><span style=""color:#A31515;"">title</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">head</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleSpanOnSameLine()
|
||||
{
|
||||
string source =
|
||||
@"<span class=""className""></span>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">span</span> <span style=""color:Red;"">class</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"className"</span><span style=""color:Blue;"">></span><span style=""color:Blue;""></</span><span style=""color:#A31515;"">span</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleElementWithIdAttribute()
|
||||
{
|
||||
string source =
|
||||
@"<table id=""bannerImageTable"" cellpadding=""0"" cellspacing=""0"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">table</span> <span style=""color:Red;"">id</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"bannerImageTable"</span> <span style=""color:Red;"">cellpadding</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"0"</span> <span style=""color:Red;"">cellspacing</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"0"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleDivElement()
|
||||
{
|
||||
string source =
|
||||
@"<div id=""anId"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">div</span> <span style=""color:Red;"">id</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"anId"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleScriptElement()
|
||||
{
|
||||
string source =
|
||||
@"<script type=""text/javascript"">var variableName = 'aString';</script>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">script</span> <span style=""color:Red;"">type</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"text/javascript"</span><span style=""color:Blue;"">></span><span style=""color:Blue;"">var</span> variableName = <span style=""color:#A31515;"">'aString'</span>;<span style=""color:Blue;""></</span><span style=""color:#A31515;"">script</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleMultiLineScriptEmbeddedInDiv()
|
||||
{
|
||||
string source =
|
||||
@"<div>
|
||||
<script type=""text/javascript"">
|
||||
var variableName = 'foo';
|
||||
|
||||
function functionName(arg1, arg2) {
|
||||
return variableName;
|
||||
}
|
||||
</script>
|
||||
</div>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">div</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">script</span> <span style=""color:Red;"">type</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"text/javascript"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;"">var</span> variableName = <span style=""color:#A31515;"">'foo'</span>;
|
||||
|
||||
<span style=""color:Blue;"">function</span> functionName(arg1, arg2) {
|
||||
<span style=""color:Blue;"">return</span> variableName;
|
||||
}
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">script</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">div</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleHtmlElementWithNamespace()
|
||||
{
|
||||
string source =
|
||||
@"<TheNameSpace:TheElementName TheAttributeName=""theAttributeValue"" />";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">TheNameSpace</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">TheElementName</span> <span style=""color:Red;"">TheAttributeName</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"theAttributeValue"</span> <span style=""color:Blue;"">/></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleDocTypeDeclaration()
|
||||
{
|
||||
string source =
|
||||
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">html</span> <span style=""color:Red;"">PUBLIC</span> <span style=""color:Blue;"">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style=""color:Blue;"">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleMetaElementWithHyphenatedAttributeName()
|
||||
{
|
||||
string source =
|
||||
@"<meta http-equiv=""Content-Type"" content=""text/html; charset=us-ascii"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">meta</span> <span style=""color:Red;"">http-equiv</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"Content-Type"</span> <span style=""color:Red;"">content</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"text/html; charset=us-ascii"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleElementWithUnquotedAttributeValue()
|
||||
{
|
||||
string source =
|
||||
@"<elementName attributeName=attributeValue />";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeName</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">attributeValue</span> <span style=""color:Blue;"">/></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnAttributeThatHasSpaceBeforeAndAfterTheEqualSign()
|
||||
{
|
||||
string source =
|
||||
@"<elementName attributeName = ""attributeValue"">someText</eElementName>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeName</span> <span style=""color:Blue;"">=</span> <span style=""color:Blue;"">"attributeValue"</span><span style=""color:Blue;"">></span>someText<span style=""color:Blue;""></</span><span style=""color:#A31515;"">eElementName</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleLargeHtmlIn1SecondOrLess()
|
||||
{
|
||||
string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
||||
string source = File.ReadAllText(Path.Combine(appPath, @"..\..\LegacyAcceptanceTests\large.html"));
|
||||
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
sw.Stop();
|
||||
TimeSpan elapsed = sw.Elapsed;
|
||||
|
||||
Assert.True(elapsed.Seconds <= 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleEntities()
|
||||
{
|
||||
string source =
|
||||
@"<elementName>></elementName>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span><span style=""color:Blue;"">></span><span style=""color:Red;"">&gt;</span><span style=""color:Blue;""></</span><span style=""color:#A31515;"">elementName</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAttributeWithUnderscore()
|
||||
{
|
||||
string source =
|
||||
@"<elementName anAttribute_Name=""attributeValue"">></elementName>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">anAttribute_Name</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"attributeValue"</span><span style=""color:Blue;"">></span><span style=""color:Red;"">&gt;</span><span style=""color:Blue;""></</span><span style=""color:#A31515;"">elementName</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleUnquotedAttributeValueFollowedByDoubleQuotedAttributeValueWithSpace()
|
||||
{
|
||||
string source =
|
||||
@"<elementName attributeName1=attributeValue attributeName2=""attribute value 2"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeName1</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">attributeValue</span> <span style=""color:Red;"">attributeName2</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"attribute value 2"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleUnquotedAttributeValueFollowingDoubleQuotedAttributeValue()
|
||||
{
|
||||
string source =
|
||||
@"<elementName attributeValue1=""attributeValue1"" attributeValue2=attributeValue2>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeValue1</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"attributeValue1"</span> <span style=""color:Red;"">attributeValue2</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">attributeValue2</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDoctypeWithLineBreakInDoubleQuotedString()
|
||||
{
|
||||
string source =
|
||||
@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML
|
||||
1.1//EN"" ""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">html</span> <span style=""color:Red;"">PUBLIC</span> <span style=""color:Blue;"">"-//W3C//DTD XHTML
|
||||
1.1//EN"</span> <span style=""color:Blue;"">"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleNumericLetterCodes()
|
||||
{
|
||||
string source =
|
||||
@"–ˆŒ";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Red;"">&#8211;</span><span style=""color:Red;"">&#710;</span><span style=""color:Red;"">&OElig;</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleScriptTags()
|
||||
{
|
||||
const string source =
|
||||
@"<script src=""/script/common.js"" type=""text/javascript""></script>
|
||||
<script src=""/script/progress.js"" type=""text/javascript""></script>";
|
||||
const string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">script</span> <span style=""color:Red;"">src</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"/script/common.js"</span> <span style=""color:Red;"">type</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"text/javascript"</span><span style=""color:Blue;"">></span><span style=""color:Blue;""></</span><span style=""color:#A31515;"">script</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">script</span> <span style=""color:Red;"">src</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"/script/progress.js"</span> <span style=""color:Red;"">type</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"text/javascript"</span><span style=""color:Blue;"">></span><span style=""color:Blue;""></</span><span style=""color:#A31515;"">script</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Html);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,182 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class JavaScriptAcceptanceTests
|
||||
{
|
||||
[Fact]
|
||||
public void TransformWillStyleVarStatement()
|
||||
{
|
||||
string source =
|
||||
@"var variableName = new VariableType();";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">var</span> variableName = <span style=""color:Blue;"">new</span> VariableType();
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleFunctionStatement()
|
||||
{
|
||||
string source =
|
||||
@"function FunctionName(argOne, argTwo) {
|
||||
return argOne + argTwo;
|
||||
}";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">function</span> FunctionName(argOne, argTwo) {
|
||||
<span style=""color:Blue;"">return</span> argOne + argTwo;
|
||||
}
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleDoubleQuotedString()
|
||||
{
|
||||
string source =
|
||||
@"var variableName = ""aString"";";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">var</span> variableName = <span style=""color:#A31515;"">"aString"</span>;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleSingleQuotedString()
|
||||
{
|
||||
string source =
|
||||
@"var variableName = 'aString';";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">var</span> variableName = <span style=""color:#A31515;"">'aString'</span>;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleCommentBlocks()
|
||||
{
|
||||
string source =
|
||||
@"/*
|
||||
comment one
|
||||
comment two
|
||||
comment three
|
||||
*/";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">/*
|
||||
comment one
|
||||
comment two
|
||||
comment three
|
||||
*/</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleLineCommentsAtStartOfLine()
|
||||
{
|
||||
string source = "// a comment.\r\n";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">// a comment.</span>
|
||||
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleLineComments()
|
||||
{
|
||||
string source =
|
||||
@"var variableName = new VariableType(); // a comment";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">var</span> variableName = <span style=""color:Blue;"">new</span> VariableType(); <span style=""color:Green;"">// a comment</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStylePrototypeOverride()
|
||||
{
|
||||
string source =
|
||||
@"if (typeof(NameSpace)!='undefined' && typeof(NameSpace.NestedNameSpace)!='undefined')
|
||||
NameSpace.NestedNameSpace.ClassName.prototype.someMethod = function () {
|
||||
return this._someValue;
|
||||
}";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">if</span> (<span style=""color:Blue;"">typeof</span>(NameSpace)!=<span style=""color:#A31515;"">'undefined'</span> && <span style=""color:Blue;"">typeof</span>(NameSpace.NestedNameSpace)!=<span style=""color:#A31515;"">'undefined'</span>)
|
||||
NameSpace.NestedNameSpace.ClassName.prototype.someMethod = <span style=""color:Blue;"">function</span> () {
|
||||
<span style=""color:Blue;"">return</span> <span style=""color:Blue;"">this</span>._someValue;
|
||||
}
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillNotAddColorToDollarSignMethod()
|
||||
{
|
||||
string source =
|
||||
@"var variableName = $(""aString"");";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">var</span> variableName = $(<span style=""color:#A31515;"">"aString"</span>);
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillCommentMultipleCommentsCorrectly()
|
||||
{
|
||||
string source =
|
||||
@"function Comment(test)
|
||||
{
|
||||
/* C style */
|
||||
// single line
|
||||
y++;
|
||||
/* C style
|
||||
multiple line */
|
||||
y++;
|
||||
// single line
|
||||
}";
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Blue;\">function</span> Comment(test)\r\n{\r\n <span style=\"color:Green;\">/* C style */</span>\r\n <span style=\"color:Green;\">// single line</span>\r\n y++;\r\n <span style=\"color:Green;\">/* C style\r\n multiple line */</span>\r\n y++;\r\n <span style=\"color:Green;\">// single line</span>\r\n}\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,170 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlClrTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleCreateAssembly()
|
||||
{
|
||||
string sourceText =
|
||||
@"DECLARE @SamplesPath nvarchar(1024)
|
||||
SELECT @SamplesPath = REPLACE(physical_name,
|
||||
'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf',
|
||||
'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\')
|
||||
FROM master.sys.database_files
|
||||
WHERE name = 'master';
|
||||
CREATE ASSEMBLY HelloWorld
|
||||
FROM @SamplesPath + 'HelloWorld\CS\HelloWorld\bin\debug\HelloWorld.dll'
|
||||
WITH PERMISSION_SET = SAFE;";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">DECLARE</span> @SamplesPath <span style=""color:Blue;"">nvarchar</span>(1024)
|
||||
<span style=""color:Blue;"">SELECT</span> @SamplesPath = <span style=""color:Magenta;"">REPLACE</span>(physical_name,
|
||||
<span style=""color:#A31515;"">'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf'</span>,
|
||||
<span style=""color:#A31515;"">'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\'</span>)
|
||||
<span style=""color:Blue;"">FROM</span> master.sys.database_files
|
||||
<span style=""color:Blue;"">WHERE</span> <span style=""color:Blue;"">name</span> = <span style=""color:#A31515;"">'master'</span>;
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">ASSEMBLY</span> HelloWorld
|
||||
<span style=""color:Blue;"">FROM</span> @SamplesPath + <span style=""color:#A31515;"">'HelloWorld\CS\HelloWorld\bin\debug\HelloWorld.dll'</span>
|
||||
<span style=""color:Blue;"">WITH</span> PERMISSION_SET = SAFE;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleAlterAssembly()
|
||||
{
|
||||
string sourceText =
|
||||
@"ALTER ASSEMBLY MyClass
|
||||
ADD FILE FROM 'C:\MyClassProject\Class1.cs';";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">ALTER</span> <span style=""color:Blue;"">ASSEMBLY</span> MyClass
|
||||
<span style=""color:Blue;"">ADD</span> <span style=""color:Blue;"">FILE</span> <span style=""color:Blue;"">FROM</span> <span style=""color:#A31515;"">'C:\MyClassProject\Class1.cs'</span>;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDropAssembly()
|
||||
{
|
||||
string sourceText =
|
||||
@"DROP ASSEMBLY Helloworld";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">ASSEMBLY</span> Helloworld
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleCreateAggregate()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
DECLARE @SamplesPath nvarchar(1024)
|
||||
-- You may have to modify the value of the this variable if you have
|
||||
--installed the sample some location other than the default location.
|
||||
SELECT @SamplesPath = REPLACE(physical_name, 'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf', 'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\')
|
||||
FROM master.sys.database_files
|
||||
WHERE name = 'master';
|
||||
CREATE ASSEMBLY StringUtilities FROM @SamplesPath + 'StringUtilities\CS\StringUtilities\bin\debug\StringUtilities.dll'
|
||||
WITH PERMISSION_SET=SAFE;
|
||||
GO
|
||||
|
||||
CREATE AGGREGATE Concatenate(@input nvarchar(4000))
|
||||
RETURNS nvarchar(4000)
|
||||
EXTERNAL NAME [StringUtilities].[Microsoft.Samples.SqlServer.Concatenate];
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">DECLARE</span> @SamplesPath <span style=""color:Blue;"">nvarchar</span>(1024)
|
||||
<span style=""color:Green;"">-- You may have to modify the value of the this variable if you have</span>
|
||||
<span style=""color:Green;"">--installed the sample some location other than the default location.</span>
|
||||
<span style=""color:Blue;"">SELECT</span> @SamplesPath = <span style=""color:Magenta;"">REPLACE</span>(physical_name, <span style=""color:#A31515;"">'Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf'</span>, <span style=""color:#A31515;"">'Microsoft SQL Server\90\Samples\Engine\Programmability\CLR\'</span>)
|
||||
<span style=""color:Blue;"">FROM</span> master.sys.database_files
|
||||
<span style=""color:Blue;"">WHERE</span> <span style=""color:Blue;"">name</span> = <span style=""color:#A31515;"">'master'</span>;
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">ASSEMBLY</span> StringUtilities <span style=""color:Blue;"">FROM</span> @SamplesPath + <span style=""color:#A31515;"">'StringUtilities\CS\StringUtilities\bin\debug\StringUtilities.dll'</span>
|
||||
<span style=""color:Blue;"">WITH</span> PERMISSION_SET=SAFE;
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">AGGREGATE</span> Concatenate(@input <span style=""color:Blue;"">nvarchar</span>(4000))
|
||||
<span style=""color:Blue;"">RETURNS</span> <span style=""color:Blue;"">nvarchar</span>(4000)
|
||||
<span style=""color:Blue;"">EXTERNAL</span> <span style=""color:Blue;"">NAME</span> [StringUtilities].[Microsoft.Samples.SqlServer.Concatenate];
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDropAggregate()
|
||||
{
|
||||
string sourceText = @"DROP AGGREGATE dbo.Concatenate";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">AGGREGATE</span> dbo.Concatenate
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleCreateType()
|
||||
{
|
||||
string sourceText = @"CREATE ASSEMBLY utf8string
|
||||
FROM '\\ComputerName\utf8string\utf8string.dll' ;
|
||||
GO
|
||||
CREATE TYPE Utf8String
|
||||
EXTERNAL NAME utf8string.[Microsoft.Samples.SqlServer.utf8string] ;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">ASSEMBLY</span> utf8string
|
||||
<span style=""color:Blue;"">FROM</span> <span style=""color:#A31515;"">'\\ComputerName\utf8string\utf8string.dll'</span> ;
|
||||
GO
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TYPE</span> Utf8String
|
||||
<span style=""color:Blue;"">EXTERNAL</span> <span style=""color:Blue;"">NAME</span> utf8string.[Microsoft.Samples.SqlServer.utf8string] ;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDropType()
|
||||
{
|
||||
string sourceText = @"DROP TYPE ssn ;";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">TYPE</span> ssn ;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlConfigurationFunctionsTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleTextsizeFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT @@TEXTSIZE AS 'Regex Size'
|
||||
SET TEXTSIZE 2048
|
||||
SELECT @@TEXTSIZE AS 'Regex Size'";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> @@TEXTSIZE <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Regex Size'</span>
|
||||
<span style=""color:Blue;"">SET</span> <span style=""color:Blue;"">TEXTSIZE</span> 2048
|
||||
<span style=""color:Blue;"">SELECT</span> @@TEXTSIZE <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Regex Size'</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,646 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlMetadataFunctionsTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleColLengthFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
CREATE TABLE t1
|
||||
(c1 varchar(40),
|
||||
c2 nvarchar(40)
|
||||
);
|
||||
GO
|
||||
SELECT COL_LENGTH('t1','c1')AS 'VarChar',
|
||||
COL_LENGTH('t1','c2')AS 'NVarChar';
|
||||
GO
|
||||
DROP TABLE t1;";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> t1
|
||||
(c1 <span style=""color:Blue;"">varchar</span>(40),
|
||||
c2 <span style=""color:Blue;"">nvarchar</span>(40)
|
||||
);
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COL_LENGTH</span>(<span style=""color:#A31515;"">'t1'</span>,<span style=""color:#A31515;"">'c1'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'VarChar'</span>,
|
||||
<span style=""color:Blue;"">COL_LENGTH</span>(<span style=""color:#A31515;"">'t1'</span>,<span style=""color:#A31515;"">'c2'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'NVarChar'</span>;
|
||||
GO
|
||||
<span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">TABLE</span> t1;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleColNameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SET NOCOUNT OFF;
|
||||
GO
|
||||
SELECT COL_NAME(OBJECT_ID('HumanResources.Employee'), 1) AS 'Column StyleName';
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SET</span> <span style=""color:Blue;"">NOCOUNT</span> <span style=""color:Blue;"">OFF</span>;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COL_NAME</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>), 1) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Column StyleName'</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleColumnPropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT COLUMNPROPERTY( OBJECT_ID('Person.Contact'),'LastName','PRECISION')AS 'Column Length';
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">COLUMNPROPERTY</span>( <span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'Person.Contact'</span>),<span style=""color:#A31515;"">'LastName'</span>,<span style=""color:#A31515;"">'PRECISION'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Column Length'</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDatabasePropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE master;
|
||||
GO
|
||||
SELECT DATABASEPROPERTY('master', 'IsTruncLog');";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> master;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">DATABASEPROPERTY</span>(<span style=""color:#A31515;"">'master'</span>, <span style=""color:#A31515;"">'IsTruncLog'</span>);
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDbIdFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT DB_ID() AS [Database ID];
|
||||
GO
|
||||
|
||||
SELECT DB_ID(N'AdventureWorks') AS [Database ID];
|
||||
GO
|
||||
|
||||
DECLARE @db_id smallint;
|
||||
DECLARE @object_id int;
|
||||
SET @db_id = DB_ID(N'AdventureWorks');
|
||||
SET @object_id = OBJECT_ID(N'AdventureWorks.Person.Address');
|
||||
IF @db_id IS NULL
|
||||
BEGIN;
|
||||
PRINT N'Invalid database';
|
||||
END;
|
||||
ELSE IF @object_id IS NULL
|
||||
BEGIN;
|
||||
PRINT N'Invalid object';
|
||||
END;
|
||||
ELSE
|
||||
BEGIN;
|
||||
SELECT * FROM sys.dm_db_index_operational_stats(@db_id, @object_id, NULL, NULL);
|
||||
END;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">DB_ID</span>() <span style=""color:Blue;"">AS</span> [Database ID];
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">DB_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks'</span>) <span style=""color:Blue;"">AS</span> [Database ID];
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">DECLARE</span> @db_id <span style=""color:Blue;"">smallint</span>;
|
||||
<span style=""color:Blue;"">DECLARE</span> @object_id <span style=""color:Blue;"">int</span>;
|
||||
<span style=""color:Blue;"">SET</span> @db_id = <span style=""color:Magenta;"">DB_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks'</span>);
|
||||
<span style=""color:Blue;"">SET</span> @object_id = <span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks.Person.Address'</span>);
|
||||
<span style=""color:Blue;"">IF</span> @db_id <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">BEGIN</span>;
|
||||
<span style=""color:Blue;"">PRINT</span> N<span style=""color:#A31515;"">'Invalid database'</span>;
|
||||
<span style=""color:Blue;"">END</span>;
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> @object_id <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">BEGIN</span>;
|
||||
<span style=""color:Blue;"">PRINT</span> N<span style=""color:#A31515;"">'Invalid object'</span>;
|
||||
<span style=""color:Blue;"">END</span>;
|
||||
<span style=""color:Blue;"">ELSE</span>
|
||||
<span style=""color:Blue;"">BEGIN</span>;
|
||||
<span style=""color:Blue;"">SELECT</span> * <span style=""color:Blue;"">FROM</span> sys.dm_db_index_operational_stats(@db_id, @object_id, <span style=""color:Blue;"">NULL</span>, <span style=""color:Blue;"">NULL</span>);
|
||||
<span style=""color:Blue;"">END</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDbNameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT DB_NAME() AS [Current Database];
|
||||
GO
|
||||
|
||||
USE master;
|
||||
GO
|
||||
SELECT DB_NAME(3)AS [Database StyleName];
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">DB_NAME</span>() <span style=""color:Blue;"">AS</span> [Current Database];
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">USE</span> master;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">DB_NAME</span>(3)<span style=""color:Blue;"">AS</span> [Database StyleName];
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFileIdFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT FILE_ID('AdventureWorks_Data')AS 'File ID';
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">FILE_ID</span>(<span style=""color:#A31515;"">'AdventureWorks_Data'</span>)<span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'File ID'</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFileNameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT FILE_NAME(1) AS 'File StyleName 1', FILE_NAME(2) AS 'File StyleName 2';
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">FILE_NAME</span>(1) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'File StyleName 1'</span>, <span style=""color:Blue;"">FILE_NAME</span>(2) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'File StyleName 2'</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFilegroupIdFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT FILEGROUP_ID('PRIMARY') AS [Filegroup ID];
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">FILEGROUP_ID</span>(<span style=""color:#A31515;"">'PRIMARY'</span>) <span style=""color:Blue;"">AS</span> [Filegroup ID];
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFilegroupNameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT FILEGROUP_NAME(1) AS [Filegroup StyleName];
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">FILEGROUP_NAME</span>(1) <span style=""color:Blue;"">AS</span> [Filegroup StyleName];
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFilegrouppropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT FILEGROUPPROPERTY('PRIMARY', 'IsDefault') AS 'DefaultStyleSheet Filegroup';
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">FILEGROUPPROPERTY</span>(<span style=""color:#A31515;"">'PRIMARY'</span>, <span style=""color:#A31515;"">'IsDefault'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'DefaultStyleSheet Filegroup'</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFilepropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT FILEPROPERTY('AdventureWorks_Data', 'IsPrimaryFile')AS [Primary File];
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">FILEPROPERTY</span>(<span style=""color:#A31515;"">'AdventureWorks_Data'</span>, <span style=""color:#A31515;"">'IsPrimaryFile'</span>)<span style=""color:Blue;"">AS</span> [Primary File];
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFulltextcatalogpropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT fulltextcatalogproperty('Cat_Desc', 'ItemCount');
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">fulltextcatalogproperty</span>(<span style=""color:#A31515;"">'Cat_Desc'</span>, <span style=""color:#A31515;"">'ItemCount'</span>);
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleFulltextservicepropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT fulltextserviceproperty('IsFulltextInstalled')";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">fulltextserviceproperty</span>(<span style=""color:#A31515;"">'IsFulltextInstalled'</span>)
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleIndexColFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT
|
||||
INDEX_COL (N'AdventureWorks.Sales.SalesOrderDetail', 1,1) AS
|
||||
[CaptureIndex Column 1],
|
||||
INDEX_COL (N'AdventureWorks.Sales.SalesOrderDetail', 1,2) AS
|
||||
[CaptureIndex Column 2]
|
||||
;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span>
|
||||
<span style=""color:Blue;"">INDEX_COL</span> (N<span style=""color:#A31515;"">'AdventureWorks.Sales.SalesOrderDetail'</span>, 1,1) <span style=""color:Blue;"">AS</span>
|
||||
[CaptureIndex Column 1],
|
||||
<span style=""color:Blue;"">INDEX_COL</span> (N<span style=""color:#A31515;"">'AdventureWorks.Sales.SalesOrderDetail'</span>, 1,2) <span style=""color:Blue;"">AS</span>
|
||||
[CaptureIndex Column 2]
|
||||
;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleIndexkeyPropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT
|
||||
INDEXKEY_PROPERTY(OBJECT_ID('Production.Location', 'U'),
|
||||
1,1,'ColumnId') AS [Column ID],
|
||||
INDEXKEY_PROPERTY(OBJECT_ID('Production.Location', 'U'),
|
||||
1,1,'IsDescending') AS [Asc or Desc order];";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span>
|
||||
<span style=""color:Blue;"">INDEXKEY_PROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'Production.Location'</span>, <span style=""color:#A31515;"">'U'</span>),
|
||||
1,1,<span style=""color:#A31515;"">'ColumnId'</span>) <span style=""color:Blue;"">AS</span> [Column ID],
|
||||
<span style=""color:Blue;"">INDEXKEY_PROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'Production.Location'</span>, <span style=""color:#A31515;"">'U'</span>),
|
||||
1,1,<span style=""color:#A31515;"">'IsDescending'</span>) <span style=""color:Blue;"">AS</span> [Asc or Desc order];
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleIndexpropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT
|
||||
INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
|
||||
'PK_Employee_EmployeeID','IsClustered')AS [Is Clustered],
|
||||
INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
|
||||
'PK_Employee_EmployeeID','IndexDepth') AS [CaptureIndex Depth],
|
||||
INDEXPROPERTY(OBJECT_ID('HumanResources.Employee'),
|
||||
'PK_Employee_EmployeeID','IndexFillFactor') AS [Fill Factor];
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span>
|
||||
<span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>),
|
||||
<span style=""color:#A31515;"">'PK_Employee_EmployeeID'</span>,<span style=""color:#A31515;"">'IsClustered'</span>)<span style=""color:Blue;"">AS</span> [Is Clustered],
|
||||
<span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>),
|
||||
<span style=""color:#A31515;"">'PK_Employee_EmployeeID'</span>,<span style=""color:#A31515;"">'IndexDepth'</span>) <span style=""color:Blue;"">AS</span> [CaptureIndex Depth],
|
||||
<span style=""color:Blue;"">INDEXPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'HumanResources.Employee'</span>),
|
||||
<span style=""color:#A31515;"">'PK_Employee_EmployeeID'</span>,<span style=""color:#A31515;"">'IndexFillFactor'</span>) <span style=""color:Blue;"">AS</span> [Fill Factor];
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleObjectIdFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE master;
|
||||
GO
|
||||
SELECT OBJECT_ID(N'AdventureWorks.Production.WorkOrder') AS 'Object ID';
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
IF OBJECT_ID (N'dbo.AWBuildVersion', N'U') IS NOT NULL
|
||||
DROP TABLE dbo.AWBuildVersion;
|
||||
GO
|
||||
|
||||
DECLARE @db_id smallint;
|
||||
DECLARE @object_id int;
|
||||
SET @db_id = DB_ID(N'AdventureWorks');
|
||||
SET @object_id = OBJECT_ID(N'AdventureWorks.Person.Address');
|
||||
IF @db_id IS NULL
|
||||
BEGIN;
|
||||
PRINT N'Invalid database';
|
||||
END;
|
||||
ELSE IF @object_id IS NULL
|
||||
BEGIN;
|
||||
PRINT N'Invalid object';
|
||||
END;
|
||||
ELSE
|
||||
BEGIN;
|
||||
SELECT * FROM sys.dm_db_index_operational_stats(@db_id, @object_id, NULL, NULL);
|
||||
END;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> master;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks.Production.WorkOrder'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Object ID'</span>;
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECT_ID</span> (N<span style=""color:#A31515;"">'dbo.AWBuildVersion'</span>, N<span style=""color:#A31515;"">'U'</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NOT</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">DROP</span> <span style=""color:Blue;"">TABLE</span> dbo.AWBuildVersion;
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">DECLARE</span> @db_id <span style=""color:Blue;"">smallint</span>;
|
||||
<span style=""color:Blue;"">DECLARE</span> @object_id <span style=""color:Blue;"">int</span>;
|
||||
<span style=""color:Blue;"">SET</span> @db_id = <span style=""color:Magenta;"">DB_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks'</span>);
|
||||
<span style=""color:Blue;"">SET</span> @object_id = <span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'AdventureWorks.Person.Address'</span>);
|
||||
<span style=""color:Blue;"">IF</span> @db_id <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">BEGIN</span>;
|
||||
<span style=""color:Blue;"">PRINT</span> N<span style=""color:#A31515;"">'Invalid database'</span>;
|
||||
<span style=""color:Blue;"">END</span>;
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> @object_id <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">BEGIN</span>;
|
||||
<span style=""color:Blue;"">PRINT</span> N<span style=""color:#A31515;"">'Invalid object'</span>;
|
||||
<span style=""color:Blue;"">END</span>;
|
||||
<span style=""color:Blue;"">ELSE</span>
|
||||
<span style=""color:Blue;"">BEGIN</span>;
|
||||
<span style=""color:Blue;"">SELECT</span> * <span style=""color:Blue;"">FROM</span> sys.dm_db_index_operational_stats(@db_id, @object_id, <span style=""color:Blue;"">NULL</span>, <span style=""color:Blue;"">NULL</span>);
|
||||
<span style=""color:Blue;"">END</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleObjectNameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT DISTINCT OBJECT_NAME(object_id)
|
||||
FROM master.sys.objects;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">DISTINCT</span> <span style=""color:Blue;"">OBJECT_NAME</span>(<span style=""color:Blue;"">object_id</span>)
|
||||
<span style=""color:Blue;"">FROM</span> master.sys.objects;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleObjectpropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
IF OBJECTPROPERTY (OBJECT_ID(N'Production.UnitMeasure'),'ISTABLE') = 1
|
||||
PRINT 'UnitMeasure is a table.'
|
||||
ELSE IF OBJECTPROPERTY (OBJECT_ID(N'Production.UnitMeasure'),'ISTABLE') = 0
|
||||
PRINT 'UnitMeasure is not a table.'
|
||||
ELSE IF OBJECTPROPERTY (OBJECT_ID(N'Production.UnitMeasure'),'ISTABLE') IS NULL
|
||||
PRINT 'ERROR: UnitMeasure is not a valid object.';
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT OBJECTPROPERTY(OBJECT_ID('dbo.ufnGetProductDealerPrice'), 'IsDeterministic');
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
SELECT name, object_id, type_desc
|
||||
FROM sys.objects
|
||||
WHERE OBJECTPROPERTY(object_id, N'SchemaId') = SCHEMA_ID(N'Production')
|
||||
ORDER BY type_desc, name;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECTPROPERTY</span> (<span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'Production.UnitMeasure'</span>),<span style=""color:#A31515;"">'ISTABLE'</span>) = 1
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'UnitMeasure is a table.'</span>
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECTPROPERTY</span> (<span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'Production.UnitMeasure'</span>),<span style=""color:#A31515;"">'ISTABLE'</span>) = 0
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'UnitMeasure is not a table.'</span>
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">OBJECTPROPERTY</span> (<span style=""color:Blue;"">OBJECT_ID</span>(N<span style=""color:#A31515;"">'Production.UnitMeasure'</span>),<span style=""color:#A31515;"">'ISTABLE'</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'ERROR: UnitMeasure is not a valid object.'</span>;
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">OBJECTPROPERTY</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'dbo.ufnGetProductDealerPrice'</span>), <span style=""color:#A31515;"">'IsDeterministic'</span>);
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">name</span>, <span style=""color:Blue;"">object_id</span>, type_desc
|
||||
<span style=""color:Blue;"">FROM</span> sys.objects
|
||||
<span style=""color:Blue;"">WHERE</span> <span style=""color:Blue;"">OBJECTPROPERTY</span>(<span style=""color:Blue;"">object_id</span>, N<span style=""color:#A31515;"">'SchemaId'</span>) = SCHEMA_ID(N<span style=""color:#A31515;"">'Production'</span>)
|
||||
<span style=""color:Blue;"">ORDER</span> <span style=""color:Blue;"">BY</span> type_desc, <span style=""color:Blue;"">name</span>;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSqlVariantPropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"CREATE TABLE tableA(colA sql_variant, colB int)
|
||||
INSERT INTO tableA values ( cast (46279.1 as decimal(8,2)), 1689)
|
||||
SELECT SQL_VARIANT_PROPERTY(colA,'BaseType') AS 'Base Type',
|
||||
SQL_VARIANT_PROPERTY(colA,'Precision') AS 'Precision',
|
||||
SQL_VARIANT_PROPERTY(colA,'Scale') AS 'Scale'
|
||||
FROM tableA
|
||||
WHERE colB = 1689";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> tableA(colA <span style=""color:Magenta;"">sql_variant</span>, colB <span style=""color:Blue;"">int</span>)
|
||||
<span style=""color:Blue;"">INSERT</span> <span style=""color:Blue;"">INTO</span> tableA <span style=""color:Blue;"">values</span> ( <span style=""color:Magenta;"">cast</span> (46279.1 <span style=""color:Blue;"">as</span> <span style=""color:Blue;"">decimal</span>(8,2)), 1689)
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">'BaseType'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Base Type'</span>,
|
||||
<span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">'Precision'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Precision'</span>,
|
||||
<span style=""color:Magenta;"">SQL_VARIANT_PROPERTY</span>(colA,<span style=""color:#A31515;"">'Scale'</span>) <span style=""color:Blue;"">AS</span> <span style=""color:#A31515;"">'Scale'</span>
|
||||
<span style=""color:Blue;"">FROM</span> tableA
|
||||
<span style=""color:Blue;"">WHERE</span> colB = 1689
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleTypepropertyFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT TYPEPROPERTY(SCHEMA_NAME(schema_id) + '.' + name, 'OwnerId') AS owner_id, name, system_type_id, user_type_id, schema_id
|
||||
FROM sys.types;
|
||||
|
||||
SELECT TYPEPROPERTY( 'tinyint', 'PRECISION');";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">TYPEPROPERTY</span>(SCHEMA_NAME(schema_id) + <span style=""color:#A31515;"">'.'</span> + <span style=""color:Blue;"">name</span>, <span style=""color:#A31515;"">'OwnerId'</span>) <span style=""color:Blue;"">AS</span> owner_id, <span style=""color:Blue;"">name</span>, system_type_id, user_type_id, schema_id
|
||||
<span style=""color:Blue;"">FROM</span> sys.types;
|
||||
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">TYPEPROPERTY</span>( <span style=""color:#A31515;"">'tinyint'</span>, <span style=""color:#A31515;"">'PRECISION'</span>);
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlPerformanceTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleLargeSourceTextIn1SecondOrLess()
|
||||
{
|
||||
string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
string source = File.ReadAllText(Path.Combine(appPath, @"..\..\LegacyAcceptanceTests\large.sql"));
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
sw.Stop();
|
||||
TimeSpan elapsed = sw.Elapsed;
|
||||
Assert.True(elapsed.Seconds <= 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,375 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlScenarioTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleSimpleSelectStatement()
|
||||
{
|
||||
string source =
|
||||
@"SELECT * FROM [TableName]";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> * <span style=""color:Blue;"">FROM</span> [TableName]
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSelectStatementWithJoin()
|
||||
{
|
||||
string source =
|
||||
@"SELECT [ColumnOneName], [ColumnTwoName] FROM [TableName] a INNER JOIN [AnotherTableName] b ON a.[ColumnName] = b.[ColumnName]";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> [ColumnOneName], [ColumnTwoName] <span style=""color:Blue;"">FROM</span> [TableName] a <span style=""color:Blue;"">INNER</span> <span style=""color:Blue;"">JOIN</span> [AnotherTableName] b <span style=""color:Blue;"">ON</span> a.[ColumnName] = b.[ColumnName]
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleInsertStatement()
|
||||
{
|
||||
string source =
|
||||
@"INSERT INTO [TableName] ([ColumnOneName], [ColumnTwoName]) VALUES ('Planned', 0)";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">INSERT</span> <span style=""color:Blue;"">INTO</span> [TableName] ([ColumnOneName], [ColumnTwoName]) <span style=""color:Blue;"">VALUES</span> (<span style=""color:#A31515;"">'Planned'</span>, 0)
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleUpdateStatement()
|
||||
{
|
||||
string source =
|
||||
@"UPDATE [TableName]
|
||||
SET [ColumnOneName] = 'value'
|
||||
WHERE [ColumnTwoName] > '2008-5-13'";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">UPDATE</span> [TableName]
|
||||
<span style=""color:Blue;"">SET</span> [ColumnOneName] = <span style=""color:#A31515;"">'value'</span>
|
||||
<span style=""color:Blue;"">WHERE</span> [ColumnTwoName] > <span style=""color:#A31515;"">'2008-5-13'</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleAlterTableStatement()
|
||||
{
|
||||
string source =
|
||||
@"ALTER TABLE [TableName]
|
||||
ADD [NewColumnName] VARCHAR(20) NOT NULL CONSTRAINT [ConstraintName] DEFAULT('DefaultValue');";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">ALTER</span> <span style=""color:Blue;"">TABLE</span> [TableName]
|
||||
<span style=""color:Blue;"">ADD</span> [NewColumnName] <span style=""color:Blue;"">VARCHAR</span>(20) <span style=""color:Blue;"">NOT</span> <span style=""color:Blue;"">NULL</span> <span style=""color:Blue;"">CONSTRAINT</span> [ConstraintName] <span style=""color:Blue;"">DEFAULT</span>(<span style=""color:#A31515;"">'DefaultValue'</span>);
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleComment()
|
||||
{
|
||||
string source =
|
||||
@"-- This is a comment.";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">-- This is a comment.</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleCommentFollowedByAnotherComment()
|
||||
{
|
||||
string source =
|
||||
@"-- This is a comment.
|
||||
-- This is another comment.";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">-- This is a comment.</span>
|
||||
<span style=""color:Green;"">-- This is another comment.</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleCreateStatementWithIdentityColumn()
|
||||
{
|
||||
string source =
|
||||
@"CREATE TABLE [TableName]
|
||||
(
|
||||
[ColumnOne] int IDENTITY(1,1),
|
||||
[ColumnTwo] varchar (20)
|
||||
)";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> [TableName]
|
||||
(
|
||||
[ColumnOne] <span style=""color:Blue;"">int</span> <span style=""color:Blue;"">IDENTITY</span>(1,1),
|
||||
[ColumnTwo] <span style=""color:Blue;"">varchar</span> (20)
|
||||
)
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSimpleCursorUseage()
|
||||
{
|
||||
string source =
|
||||
@"USE databaseName
|
||||
GO
|
||||
|
||||
DECLARE @columnNameOne varchar(50)
|
||||
|
||||
DECLARE cursorName CURSOR FOR
|
||||
SELECT columnNameOne FROM tableName
|
||||
WHERE columnNameOne LIKE 'SomeText'
|
||||
ORDER BY columnNameOne
|
||||
|
||||
OPEN cursorName
|
||||
|
||||
FETCH NEXT FROM cursorName
|
||||
INTO @columnNameOne
|
||||
|
||||
WHILE @@FETCH_STATUS = 0
|
||||
BEGIN
|
||||
PRINT 'Column StyleName One: ' + @columnOneName
|
||||
|
||||
FETCH NEXT FROM cursorName
|
||||
INTO @columnNameOne
|
||||
END
|
||||
|
||||
CLOSE cursorName
|
||||
DEALLOCATE cursorName
|
||||
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> databaseName
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">DECLARE</span> @columnNameOne <span style=""color:Blue;"">varchar</span>(50)
|
||||
|
||||
<span style=""color:Blue;"">DECLARE</span> cursorName <span style=""color:Blue;"">CURSOR</span> <span style=""color:Blue;"">FOR</span>
|
||||
<span style=""color:Blue;"">SELECT</span> columnNameOne <span style=""color:Blue;"">FROM</span> tableName
|
||||
<span style=""color:Blue;"">WHERE</span> columnNameOne <span style=""color:Blue;"">LIKE</span> <span style=""color:#A31515;"">'SomeText'</span>
|
||||
<span style=""color:Blue;"">ORDER</span> <span style=""color:Blue;"">BY</span> columnNameOne
|
||||
|
||||
<span style=""color:Blue;"">OPEN</span> cursorName
|
||||
|
||||
<span style=""color:Blue;"">FETCH</span> <span style=""color:Blue;"">NEXT</span> <span style=""color:Blue;"">FROM</span> cursorName
|
||||
<span style=""color:Blue;"">INTO</span> @columnNameOne
|
||||
|
||||
<span style=""color:Blue;"">WHILE</span> <span style=""color:Magenta;"">@@FETCH_STATUS</span> = 0
|
||||
<span style=""color:Blue;"">BEGIN</span>
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'Column StyleName One: '</span> + @columnOneName
|
||||
|
||||
<span style=""color:Blue;"">FETCH</span> <span style=""color:Blue;"">NEXT</span> <span style=""color:Blue;"">FROM</span> cursorName
|
||||
<span style=""color:Blue;"">INTO</span> @columnNameOne
|
||||
<span style=""color:Blue;"">END</span>
|
||||
|
||||
<span style=""color:Blue;"">CLOSE</span> cursorName
|
||||
<span style=""color:Blue;"">DEALLOCATE</span> cursorName
|
||||
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSimpleCreateProcedureStatement()
|
||||
{
|
||||
string source =
|
||||
@"CREATE PROCEDURE procedureName
|
||||
AS
|
||||
SELECT columnName
|
||||
FROM tableName;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">PROCEDURE</span> procedureName
|
||||
<span style=""color:Blue;"">AS</span>
|
||||
<span style=""color:Blue;"">SELECT</span> columnName
|
||||
<span style=""color:Blue;"">FROM</span> tableName;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSimpleCreateProcStatement()
|
||||
{
|
||||
string source =
|
||||
@"CREATE PROC procedureName
|
||||
AS
|
||||
SELECT columnName
|
||||
FROM tableName;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">PROC</span> procedureName
|
||||
<span style=""color:Blue;"">AS</span>
|
||||
<span style=""color:Blue;"">SELECT</span> columnName
|
||||
<span style=""color:Blue;"">FROM</span> tableName;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillNotStyleKeywordInsideStraightBraces()
|
||||
{
|
||||
string source =
|
||||
@"[SELECT]";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
[SELECT]
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillNotStyleKeywordsPrecededByAtSign()
|
||||
{
|
||||
string source =
|
||||
@"@size";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
@size
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillNotStyleKeywordsPrecededByAtDot()
|
||||
{
|
||||
string source =
|
||||
@"aliasName.StyleName";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
aliasName.StyleName
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillNotStyleKeywordInsideStraightBracesWithSpaceBeforeAndAfter()
|
||||
{
|
||||
string source =
|
||||
@"[ SELECT ]";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
[ SELECT ]
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleMultiLineString()
|
||||
{
|
||||
string source =
|
||||
@"SET @doc ='
|
||||
<ROOT>
|
||||
<Customer CustomerID=""VINET"" ContactName=""Paul Henriot"">
|
||||
<Order CustomerID=""VINET"" EmployeeID=""5"" OrderDate=""1996-07-04T00:00:00"">
|
||||
<OrderDetail OrderID=""10248"" ProductID=""11"" Quantity=""12""/>
|
||||
<OrderDetail OrderID=""10248"" ProductID=""42"" Quantity=""10""/>
|
||||
</Order>
|
||||
</Customer>
|
||||
<Customer CustomerID=""LILAS"" ContactName=""Carlos Gonzlez"">
|
||||
<Order CustomerID=""LILAS"" EmployeeID=""3"" OrderDate=""1996-08-16T00:00:00"">
|
||||
<OrderDetail OrderID=""10283"" ProductID=""72"" Quantity=""3""/>
|
||||
</Order>
|
||||
</Customer>
|
||||
</ROOT>'";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SET</span> @doc =<span style=""color:#A31515;"">'
|
||||
<ROOT>
|
||||
<Customer CustomerID="VINET" ContactName="Paul Henriot">
|
||||
<Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00">
|
||||
<OrderDetail OrderID="10248" ProductID="11" Quantity="12"/>
|
||||
<OrderDetail OrderID="10248" ProductID="42" Quantity="10"/>
|
||||
</Order>
|
||||
</Customer>
|
||||
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
|
||||
<Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00">
|
||||
<OrderDetail OrderID="10283" ProductID="72" Quantity="3"/>
|
||||
</Order>
|
||||
</Customer>
|
||||
</ROOT>'</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleDoubleQuotedLineString()
|
||||
{
|
||||
string source =
|
||||
@"SELECT ""foo""";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:#A31515;"">"foo"</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlSecurityFunctionsTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStyleIsMemberFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"-- Test membership in db_owner and print appropriate message.
|
||||
IF IS_MEMBER ('db_owner') = 1
|
||||
print 'Current user is a member of the db_owner role'
|
||||
ELSE IF IS_MEMBER ('db_owner') = 0
|
||||
print 'Current user is NOT a member of the db_owner role'
|
||||
ELSE IF IS_MEMBER ('db_owner') IS NULL
|
||||
print 'ERROR: Invalid group / role specified'
|
||||
go
|
||||
|
||||
-- Execute SELECT if user is a member of ADVWORKS\Shipping.
|
||||
IF IS_MEMBER ('ADVWORKS\Shipping') = 1
|
||||
SELECT 'User ' + USER + ' is a member of ADVWORKS\Shipping.'
|
||||
go";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">-- Test membership in db_owner and print appropriate message.</span>
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">'db_owner'</span>) = 1
|
||||
<span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">'Current user is a member of the db_owner role'</span>
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">'db_owner'</span>) = 0
|
||||
<span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">'Current user is NOT a member of the db_owner role'</span>
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">'db_owner'</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">'ERROR: Invalid group / role specified'</span>
|
||||
go
|
||||
|
||||
<span style=""color:Green;"">-- Execute SELECT if user is a member of ADVWORKS\Shipping.</span>
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_MEMBER</span> (<span style=""color:#A31515;"">'ADVWORKS\Shipping'</span>) = 1
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:#A31515;"">'User '</span> + <span style=""color:Magenta;"">USER</span> + <span style=""color:#A31515;"">' is a member of ADVWORKS\Shipping.'</span>
|
||||
go
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSuserSidFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
CREATE TABLE sid_example
|
||||
(
|
||||
login_sid varbinary(85) DEFAULT SUSER_SID(),
|
||||
login_name varchar(30) DEFAULT SYSTEM_USER,
|
||||
login_dept varchar(10) DEFAULT 'SALES',
|
||||
login_date datetime DEFAULT GETDATE()
|
||||
)
|
||||
GO
|
||||
INSERT sid_example DEFAULT VALUES
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> sid_example
|
||||
(
|
||||
login_sid <span style=""color:Blue;"">varbinary</span>(85) <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Blue;"">SUSER_SID</span>(),
|
||||
login_name <span style=""color:Blue;"">varchar</span>(30) <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Magenta;"">SYSTEM_USER</span>,
|
||||
login_dept <span style=""color:Blue;"">varchar</span>(10) <span style=""color:Blue;"">DEFAULT</span> <span style=""color:#A31515;"">'SALES'</span>,
|
||||
login_date <span style=""color:Blue;"">datetime</span> <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Magenta;"">GETDATE</span>()
|
||||
)
|
||||
GO
|
||||
<span style=""color:Blue;"">INSERT</span> sid_example <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Blue;"">VALUES</span>
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSuserSnameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT SUSER_SNAME(0x01);
|
||||
GO
|
||||
|
||||
SELECT SUSER_SNAME(0x010500000000000515000000a065cf7e784b9b5fe77c87705a2e0000);
|
||||
GO
|
||||
|
||||
USE AdventureWorks;
|
||||
GO
|
||||
CREATE TABLE sname_example
|
||||
(
|
||||
login_sname sysname DEFAULT SUSER_SNAME(),
|
||||
employee_id uniqueidentifier DEFAULT NEWID(),
|
||||
login_date datetime DEFAULT GETDATE()
|
||||
)
|
||||
GO
|
||||
INSERT sname_example DEFAULT VALUES
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">SUSER_SNAME</span>(0x01);
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Blue;"">SUSER_SNAME</span>(0x010500000000000515000000a065cf7e784b9b5fe77c87705a2e0000);
|
||||
GO
|
||||
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> sname_example
|
||||
(
|
||||
login_sname <span style=""color:Blue;"">sysname</span> <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Blue;"">SUSER_SNAME</span>(),
|
||||
employee_id <span style=""color:Blue;"">uniqueidentifier</span> <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Magenta;"">NEWID</span>(),
|
||||
login_date <span style=""color:Blue;"">datetime</span> <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Magenta;"">GETDATE</span>()
|
||||
)
|
||||
GO
|
||||
<span style=""color:Blue;"">INSERT</span> sname_example <span style=""color:Blue;"">DEFAULT</span> <span style=""color:Blue;"">VALUES</span>
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleIsSrvrolememberFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"IF IS_SRVROLEMEMBER ('sysadmin') = 1
|
||||
print 'Current user''s login is a member of the sysadmin role'
|
||||
ELSE IF IS_SRVROLEMEMBER ('sysadmin') = 0
|
||||
print 'Current user''s login is NOT a member of the sysadmin role'
|
||||
ELSE IF IS_SRVROLEMEMBER ('sysadmin') IS NULL
|
||||
print 'ERROR: The server role specified is not valid.'";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_SRVROLEMEMBER</span> (<span style=""color:#A31515;"">'sysadmin'</span>) = 1
|
||||
<span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">'Current user'</span><span style=""color:#A31515;"">'s login is a member of the sysadmin role'</span>
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_SRVROLEMEMBER</span> (<span style=""color:#A31515;"">'sysadmin'</span>) = 0
|
||||
<span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">'Current user'</span><span style=""color:#A31515;"">'s login is NOT a member of the sysadmin role'</span>
|
||||
<span style=""color:Blue;"">ELSE</span> <span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">IS_SRVROLEMEMBER</span> (<span style=""color:#A31515;"">'sysadmin'</span>) <span style=""color:Blue;"">IS</span> <span style=""color:Blue;"">NULL</span>
|
||||
<span style=""color:Blue;"">print</span> <span style=""color:#A31515;"">'ERROR: The server role specified is not valid.'</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStylePermissionsFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"IF PERMISSIONS()&2=2
|
||||
CREATE TABLE test_table (col1 INT)
|
||||
ELSE
|
||||
PRINT 'ERROR: The current user cannot create a table.';
|
||||
|
||||
IF PERMISSIONS(OBJECT_ID('AdventureWorks.Person.Address','U'))&8=8
|
||||
PRINT 'The current user can insert data into Person.Address.'
|
||||
ELSE
|
||||
PRINT 'ERROR: The current user cannot insert data into Person.Address.';
|
||||
|
||||
IF PERMISSIONS(OBJECT_ID('AdventureWorks.Person.Address','U'))&0x80000=0x80000
|
||||
PRINT 'INSERT on Person.Address is grantable.'
|
||||
ELSE
|
||||
PRINT 'You may not GRANT INSERT permissions on Person.Address.';";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">PERMISSIONS</span>()&2=2
|
||||
<span style=""color:Blue;"">CREATE</span> <span style=""color:Blue;"">TABLE</span> test_table (col1 <span style=""color:Blue;"">INT</span>)
|
||||
<span style=""color:Blue;"">ELSE</span>
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'ERROR: The current user cannot create a table.'</span>;
|
||||
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">PERMISSIONS</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'AdventureWorks.Person.Address'</span>,<span style=""color:#A31515;"">'U'</span>))&8=8
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'The current user can insert data into Person.Address.'</span>
|
||||
<span style=""color:Blue;"">ELSE</span>
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'ERROR: The current user cannot insert data into Person.Address.'</span>;
|
||||
|
||||
<span style=""color:Blue;"">IF</span> <span style=""color:Blue;"">PERMISSIONS</span>(<span style=""color:Blue;"">OBJECT_ID</span>(<span style=""color:#A31515;"">'AdventureWorks.Person.Address'</span>,<span style=""color:#A31515;"">'U'</span>))&0x80000=0x80000
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'INSERT on Person.Address is grantable.'</span>
|
||||
<span style=""color:Blue;"">ELSE</span>
|
||||
<span style=""color:Blue;"">PRINT</span> <span style=""color:#A31515;"">'You may not GRANT INSERT permissions on Person.Address.'</span>;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleSuserNameFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"SELECT SUSER_NAME(1)";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">SUSER_NAME</span>(1)
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode.SqlAcceptanceTests
|
||||
{
|
||||
public class SqlTextAndImageFunctionsTests
|
||||
{
|
||||
public class Transform
|
||||
{
|
||||
[Fact]
|
||||
public void WillStylePatIndexFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE AdventureWorks;
|
||||
GO
|
||||
SELECT PATINDEX('%ensure%',DocumentSummary)
|
||||
FROM Production.Document
|
||||
WHERE DocumentID = 3;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> AdventureWorks;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> <span style=""color:Magenta;"">PATINDEX</span>(<span style=""color:#A31515;"">'%ensure%'</span>,DocumentSummary)
|
||||
<span style=""color:Blue;"">FROM</span> Production.Document
|
||||
<span style=""color:Blue;"">WHERE</span> DocumentID = 3;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleTextValidFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE pubs;
|
||||
GO
|
||||
SELECT pub_id, 'Valid (if 1) Regex data'
|
||||
= TEXTVALID ('pub_info.logo', TEXTPTR(logo))
|
||||
FROM pub_info
|
||||
ORDER BY pub_id;
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> pubs;
|
||||
GO
|
||||
<span style=""color:Blue;"">SELECT</span> pub_id, <span style=""color:#A31515;"">'Valid (if 1) Regex data'</span>
|
||||
= <span style=""color:Blue;"">TEXTVALID</span> (<span style=""color:#A31515;"">'pub_info.logo'</span>, <span style=""color:Blue;"">TEXTPTR</span>(logo))
|
||||
<span style=""color:Blue;"">FROM</span> pub_info
|
||||
<span style=""color:Blue;"">ORDER</span> <span style=""color:Blue;"">BY</span> pub_id;
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WillStyleTextPtrFunction()
|
||||
{
|
||||
string sourceText =
|
||||
@"USE pubs
|
||||
GO
|
||||
DECLARE @ptrval varbinary(16)
|
||||
SELECT @ptrval = TEXTPTR(logo)
|
||||
FROM pub_info pr, publishers p
|
||||
WHERE p.pub_id = pr.pub_id
|
||||
AND p.pub_name = 'New Moon Books'
|
||||
GO";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">USE</span> pubs
|
||||
GO
|
||||
<span style=""color:Blue;"">DECLARE</span> @ptrval <span style=""color:Blue;"">varbinary</span>(16)
|
||||
<span style=""color:Blue;"">SELECT</span> @ptrval = <span style=""color:Blue;"">TEXTPTR</span>(logo)
|
||||
<span style=""color:Blue;"">FROM</span> pub_info pr, publishers p
|
||||
<span style=""color:Blue;"">WHERE</span> p.pub_id = pr.pub_id
|
||||
<span style=""color:Blue;"">AND</span> p.pub_name = <span style=""color:#A31515;"">'New Moon Books'</span>
|
||||
GO
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(sourceText, Languages.Sql);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,522 +0,0 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class VbDotNetAcceptanceTests
|
||||
{
|
||||
[Fact]
|
||||
public void TransformWillStyleImportStatement()
|
||||
{
|
||||
string source =
|
||||
@"Imports System";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Imports</span> System
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleImportStatementWithNestedNamespace()
|
||||
{
|
||||
string source =
|
||||
@"Imports System.Regex";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Imports</span> System.Regex
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleNamespaceStatement()
|
||||
{
|
||||
string source =
|
||||
@" Namespace My.Namespace";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Namespace</span> <span style=""color:Blue;"">My</span>.<span style=""color:Blue;"">Namespace</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleDocComments()
|
||||
{
|
||||
string source =
|
||||
@"''' <summary>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">''' <summary></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleComments()
|
||||
{
|
||||
string source =
|
||||
@"' this is a comment";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Green;"">' this is a comment</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleDoubleQuotesStrings()
|
||||
{
|
||||
string source =
|
||||
@"""this is a double-quoted string""";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:#A31515;"">"this is a double-quoted string"</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleClassDeclaration()
|
||||
{
|
||||
string source =
|
||||
@"Public Class SomeClass
|
||||
Inherits SomeOtherClass
|
||||
Implements SomeInterface
|
||||
End Class";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Public</span> <span style=""color:Blue;"">Class</span> SomeClass
|
||||
<span style=""color:Blue;"">Inherits</span> SomeOtherClass
|
||||
<span style=""color:Blue;"">Implements</span> SomeInterface
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Class</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleVariableDeclaration()
|
||||
{
|
||||
string source =
|
||||
@"Private Const SomeVariable As String = ""SomeValue""";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Private</span> <span style=""color:Blue;"">Const</span> SomeVariable <span style=""color:Blue;"">As</span> <span style=""color:Blue;"">String</span> = <span style=""color:#A31515;"">"SomeValue"</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleSubBlock()
|
||||
{
|
||||
string source =
|
||||
@"Protected Overridable Sub SomeEventHandler(ByVal e As EventArgs)
|
||||
If Not SomeEvent Is Nothing Then
|
||||
RaiseEvent Some(Me, e)
|
||||
End If
|
||||
End Sub";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Protected</span> <span style=""color:Blue;"">Overridable</span> <span style=""color:Blue;"">Sub</span> SomeEventHandler(<span style=""color:Blue;"">ByVal</span> e <span style=""color:Blue;"">As</span> EventArgs)
|
||||
<span style=""color:Blue;"">If</span> <span style=""color:Blue;"">Not</span> SomeEvent <span style=""color:Blue;"">Is</span> <span style=""color:Blue;"">Nothing</span> <span style=""color:Blue;"">Then</span>
|
||||
<span style=""color:Blue;"">RaiseEvent</span> Some(<span style=""color:Blue;"">Me</span>, e)
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">If</span>
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleCastingFunctions()
|
||||
{
|
||||
string source =
|
||||
@"CBool(foo)
|
||||
CByte(foo)
|
||||
CChar(foo)
|
||||
CDate(foo)
|
||||
CDec(foo)
|
||||
CDbl(foo)
|
||||
Char(foo)
|
||||
CInt(foo)
|
||||
CLng(foo)
|
||||
CObj(foo)
|
||||
CShort(foo)
|
||||
CSng(foo)
|
||||
CStr(foo)
|
||||
CSByte(foo)
|
||||
CUInt(foo)
|
||||
CULng(foo)
|
||||
CUShort(foo)";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">CBool</span>(foo)
|
||||
<span style=""color:Blue;"">CByte</span>(foo)
|
||||
<span style=""color:Blue;"">CChar</span>(foo)
|
||||
<span style=""color:Blue;"">CDate</span>(foo)
|
||||
<span style=""color:Blue;"">CDec</span>(foo)
|
||||
<span style=""color:Blue;"">CDbl</span>(foo)
|
||||
<span style=""color:Blue;"">Char</span>(foo)
|
||||
<span style=""color:Blue;"">CInt</span>(foo)
|
||||
<span style=""color:Blue;"">CLng</span>(foo)
|
||||
<span style=""color:Blue;"">CObj</span>(foo)
|
||||
<span style=""color:Blue;"">CShort</span>(foo)
|
||||
<span style=""color:Blue;"">CSng</span>(foo)
|
||||
<span style=""color:Blue;"">CStr</span>(foo)
|
||||
<span style=""color:Blue;"">CSByte</span>(foo)
|
||||
<span style=""color:Blue;"">CUInt</span>(foo)
|
||||
<span style=""color:Blue;"">CULng</span>(foo)
|
||||
<span style=""color:Blue;"">CUShort</span>(foo)
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleTypeNames()
|
||||
{
|
||||
string source =
|
||||
@"String
|
||||
Date
|
||||
Decimal
|
||||
Double
|
||||
Enum
|
||||
Integer
|
||||
Long
|
||||
Short
|
||||
Single
|
||||
Boolean
|
||||
Byte
|
||||
SByte
|
||||
UInteger
|
||||
ULong
|
||||
UShort
|
||||
Char
|
||||
Structure";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">String</span>
|
||||
<span style=""color:Blue;"">Date</span>
|
||||
<span style=""color:Blue;"">Decimal</span>
|
||||
<span style=""color:Blue;"">Double</span>
|
||||
<span style=""color:Blue;"">Enum</span>
|
||||
<span style=""color:Blue;"">Integer</span>
|
||||
<span style=""color:Blue;"">Long</span>
|
||||
<span style=""color:Blue;"">Short</span>
|
||||
<span style=""color:Blue;"">Single</span>
|
||||
<span style=""color:Blue;"">Boolean</span>
|
||||
<span style=""color:Blue;"">Byte</span>
|
||||
<span style=""color:Blue;"">SByte</span>
|
||||
<span style=""color:Blue;"">UInteger</span>
|
||||
<span style=""color:Blue;"">ULong</span>
|
||||
<span style=""color:Blue;"">UShort</span>
|
||||
<span style=""color:Blue;"">Char</span>
|
||||
<span style=""color:Blue;"">Structure</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAddHandlerStatement()
|
||||
{
|
||||
string source =
|
||||
@"AddHandler event, AddressOf eventHandler";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">AddHandler</span> <span style=""color:Blue;"">event</span>, <span style=""color:Blue;"">AddressOf</span> eventHandler
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleDeclareStatement()
|
||||
{
|
||||
string source =
|
||||
@"Declare Function FunctioName Lib ""some.dll"" Alias ""FunctionNameInDll"" (ByVal arg1 As String, ByRef arg2 As Integer) As Integer";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Declare</span> <span style=""color:Blue;"">Function</span> FunctioName <span style=""color:Blue;"">Lib</span> <span style=""color:#A31515;"">"some.dll"</span> <span style=""color:Blue;"">Alias</span> <span style=""color:#A31515;"">"FunctionNameInDll"</span> (<span style=""color:Blue;"">ByVal</span> arg1 <span style=""color:Blue;"">As</span> <span style=""color:Blue;"">String</span>, <span style=""color:Blue;"">ByRef</span> arg2 <span style=""color:Blue;"">As</span> <span style=""color:Blue;"">Integer</span>) <span style=""color:Blue;"">As</span> <span style=""color:Blue;"">Integer</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillNotStyleObjectInSystemDotObject()
|
||||
{
|
||||
string source =
|
||||
@"System.Object";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
System.Object
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleObjectInDimStatement()
|
||||
{
|
||||
string source =
|
||||
@"Dim foo as Object";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Dim</span> foo <span style=""color:Blue;"">as</span> <span style=""color:Blue;"">Object</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleLowerCaseKeywords()
|
||||
{
|
||||
string source =
|
||||
@"dim foo as object";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">dim</span> foo <span style=""color:Blue;"">as</span> <span style=""color:Blue;"">object</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillNotStyleAssemblyKeywordInAttribute()
|
||||
{
|
||||
string source =
|
||||
@"<Assembly: CLSCompliant(True)>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<Assembly: CLSCompliant(<span style=""color:Blue;"">True</span>)>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleRegionAndIfDirectives()
|
||||
{
|
||||
string source =
|
||||
@"#Region ""A comment""
|
||||
' this is a comment
|
||||
#End Region
|
||||
#If
|
||||
#Else
|
||||
#End If";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">#Region</span> <span style=""color:#A31515;"">"A comment"</span>
|
||||
<span style=""color:Green;"">' this is a comment</span>
|
||||
<span style=""color:Blue;"">#End Region</span>
|
||||
<span style=""color:Blue;"">#If</span>
|
||||
<span style=""color:Blue;"">#Else</span>
|
||||
<span style=""color:Blue;"">#End If</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleRemoveHandlerStatement()
|
||||
{
|
||||
string source =
|
||||
@"Sub TestEvents()
|
||||
Dim Obj As New Class1
|
||||
' Associate an event handler with an event.
|
||||
AddHandler Obj.Ev_Event, AddressOf EventHandler
|
||||
' Call the method to raise the event.
|
||||
Obj.CauseSomeEvent()
|
||||
' Stop handling events.
|
||||
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
|
||||
' This event will not be handled.
|
||||
Obj.CauseSomeEvent()
|
||||
End Sub
|
||||
|
||||
Sub EventHandler()
|
||||
' Handle the event.
|
||||
MsgBox(""EventHandler caught event."")
|
||||
End Sub
|
||||
|
||||
Public Class Class1
|
||||
' Declare an event.
|
||||
Public Event Ev_Event()
|
||||
Sub CauseSomeEvent()
|
||||
' Raise an event.
|
||||
RaiseEvent Ev_Event()
|
||||
End Sub
|
||||
End Class";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Sub</span> TestEvents()
|
||||
<span style=""color:Blue;"">Dim</span> Obj <span style=""color:Blue;"">As</span> <span style=""color:Blue;"">New</span> Class1
|
||||
<span style=""color:Green;"">' Associate an event handler with an event.</span>
|
||||
<span style=""color:Blue;"">AddHandler</span> Obj.Ev_Event, <span style=""color:Blue;"">AddressOf</span> EventHandler
|
||||
<span style=""color:Green;"">' Call the method to raise the event.</span>
|
||||
Obj.CauseSomeEvent()
|
||||
<span style=""color:Green;"">' Stop handling events.</span>
|
||||
<span style=""color:Blue;"">RemoveHandler</span> Obj.Ev_Event, <span style=""color:Blue;"">AddressOf</span> EventHandler
|
||||
<span style=""color:Green;"">' This event will not be handled.</span>
|
||||
Obj.CauseSomeEvent()
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
|
||||
<span style=""color:Blue;"">Sub</span> EventHandler()
|
||||
<span style=""color:Green;"">' Handle the event.</span>
|
||||
MsgBox(<span style=""color:#A31515;"">"EventHandler caught event."</span>)
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
|
||||
<span style=""color:Blue;"">Public</span> <span style=""color:Blue;"">Class</span> Class1
|
||||
<span style=""color:Green;"">' Declare an event.</span>
|
||||
<span style=""color:Blue;"">Public</span> <span style=""color:Blue;"">Event</span> Ev_Event()
|
||||
<span style=""color:Blue;"">Sub</span> CauseSomeEvent()
|
||||
<span style=""color:Green;"">' Raise an event.</span>
|
||||
<span style=""color:Blue;"">RaiseEvent</span> Ev_Event()
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Class</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleRemStatement()
|
||||
{
|
||||
string source =
|
||||
@"Dim demoStr1, demoStr2 As String
|
||||
demoStr1 = ""Hello"" REM Comment after a statement using REM.
|
||||
demoStr2 = ""Goodbye"" ' Comment after a statement using the ' character.
|
||||
REM This entire line is a comment.
|
||||
' This entire line is also a comment.";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Dim</span> demoStr1, demoStr2 <span style=""color:Blue;"">As</span> <span style=""color:Blue;"">String</span>
|
||||
demoStr1 = <span style=""color:#A31515;"">"Hello"</span> <span style=""color:Green;"">REM Comment after a statement using REM.</span>
|
||||
demoStr2 = <span style=""color:#A31515;"">"Goodbye"</span> <span style=""color:Green;"">' Comment after a statement using the ' character.</span>
|
||||
<span style=""color:Green;"">REM This entire line is a comment.</span>
|
||||
<span style=""color:Green;"">' This entire line is also a comment.</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleExternalSourceDirectiveNoSpaceBeforeParenthesis()
|
||||
{
|
||||
string source =
|
||||
@"#ExternalSource(""C:\Documents and Settings\ITO-User\My Documents\Visual Studio 2005\WebSites\WebSite1\Next.aspx"",10)
|
||||
Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm
|
||||
#End ExternalSource";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">#ExternalSource</span>(<span style=""color:#A31515;"">"C:\Documents and Settings\ITO-User\My Documents\Visual Studio 2005\WebSites\WebSite1\Next.aspx"</span>,10)
|
||||
<span style=""color:Blue;"">Protected</span> <span style=""color:Blue;"">WithEvents</span> form1 <span style=""color:Blue;"">As</span> Global.System.Web.UI.HtmlControls.HtmlForm
|
||||
<span style=""color:Blue;"">#End ExternalSource</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleExternalSourceDirectiveWithSpaceBeforeParenthesis()
|
||||
{
|
||||
string source =
|
||||
@"#ExternalSource (""C:\Documents and Settings\ITO-User\My Documents\Visual Studio 2005\WebSites\WebSite1\Next.aspx"",10)
|
||||
Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm
|
||||
#End ExternalSource";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">#ExternalSource</span> (<span style=""color:#A31515;"">"C:\Documents and Settings\ITO-User\My Documents\Visual Studio 2005\WebSites\WebSite1\Next.aspx"</span>,10)
|
||||
<span style=""color:Blue;"">Protected</span> <span style=""color:Blue;"">WithEvents</span> form1 <span style=""color:Blue;"">As</span> Global.System.Web.UI.HtmlControls.HtmlForm
|
||||
<span style=""color:Blue;"">#End ExternalSource</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStylePartialClassesAndMethods()
|
||||
{
|
||||
string source =
|
||||
@"Partial Class Customer
|
||||
Partial Private Sub OnNameChanged()
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Partial Class Customer
|
||||
Private Sub OnNameChanged()
|
||||
End Sub
|
||||
End Class";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;"">Partial</span> <span style=""color:Blue;"">Class</span> Customer
|
||||
<span style=""color:Blue;"">Partial</span> <span style=""color:Blue;"">Private</span> <span style=""color:Blue;"">Sub</span> OnNameChanged()
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Class</span>
|
||||
|
||||
<span style=""color:Blue;"">Partial</span> <span style=""color:Blue;"">Class</span> Customer
|
||||
<span style=""color:Blue;"">Private</span> <span style=""color:Blue;"">Sub</span> OnNameChanged()
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Sub</span>
|
||||
<span style=""color:Blue;"">End</span> <span style=""color:Blue;"">Class</span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
using Xunit;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class XmlAcceptanceTests
|
||||
{
|
||||
[Fact]
|
||||
public void TransformWillStyleASimpleElement()
|
||||
{
|
||||
string source =
|
||||
@"<fnord>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">fnord</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleElementAttributes()
|
||||
{
|
||||
string source =
|
||||
@"<elementName attributeName=""attributeValue"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeName</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">attributeValue</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleXmlPreProcessor()
|
||||
{
|
||||
string source =
|
||||
@"<?xml version=""1.0"" encoding=""UTF-8""?>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><?</span><span style=""color:#A31515;"">xml</span> <span style=""color:Red;"">version</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">1.0</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">encoding</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">UTF-8</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">?></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleEntities()
|
||||
{
|
||||
string source =
|
||||
@"<string>></string>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">string</span><span style=""color:Blue;"">></span><span style=""color:Red;"">&gt;</span><span style=""color:Blue;""></</span><span style=""color:#A31515;"">string</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnElementNameThatContainsAPeriod()
|
||||
{
|
||||
string source =
|
||||
@"<anElement.StyleName>someText</anElement.StyleName>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">anElement.StyleName</span><span style=""color:Blue;"">></span>someText<span style=""color:Blue;""></</span><span style=""color:#A31515;"">anElement.StyleName</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnAttributeThatHasSpaceBeforeAndAfterTheEqualSign()
|
||||
{
|
||||
string source =
|
||||
@"<elementName attributeName = ""attributeValue"">someText</eElementName>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeName</span> <span style=""color:Blue;"">=</span> <span style=""color:Black;"">"</span><span style=""color:Blue;"">attributeValue</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">></span>someText<span style=""color:Blue;""></</span><span style=""color:#A31515;"">eElementName</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnElementWithANamespacePrefix()
|
||||
{
|
||||
string source =
|
||||
@"<namespaceName:elementName attributeName = ""attributeValue"" />";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">namespaceName</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">elementName</span> <span style=""color:Red;"">attributeName</span> <span style=""color:Blue;"">=</span> <span style=""color:Black;"">"</span><span style=""color:Blue;"">attributeValue</span><span style=""color:Black;"">"</span> <span style=""color:Blue;"">/></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnElementWithANamespaceAndAttributeWithNameSpace()
|
||||
{
|
||||
string source =
|
||||
@"<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"" targetNamespace=""http://tempuri.org/po.xsd""
|
||||
xmlns=""http://tempuri.org/po.xsd"" elementFormDefault=""qualified"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">xs</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">schema</span> <span style=""color:Red;"">xmlns:xs</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">http://www.w3.org/2001/XMLSchema</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">targetNamespace</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">http://tempuri.org/po.xsd</span><span style=""color:Black;"">"</span>
|
||||
<span style=""color:Red;"">xmlns</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">http://tempuri.org/po.xsd</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">elementFormDefault</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">qualified</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleXmlElementsContainingAHyphen()
|
||||
{
|
||||
string source =
|
||||
@"<xsl:for-each select=""x | y/x"">";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">xsl</span><span style=""color:Blue;"">:</span><span style=""color:#A31515;"">for-each</span> <span style=""color:Red;"">select</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">x | y/x</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleXmlCDATA()
|
||||
{
|
||||
string source =
|
||||
@"<?xml version=""1.0"" encoding=""iso-8859-1"" standalone=""yes""?>
|
||||
<catalog>
|
||||
<![CDATA[An in-depth look at creating applications with XML, using <, >,]]>
|
||||
</catalog>;";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><?</span><span style=""color:#A31515;"">xml</span> <span style=""color:Red;"">version</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">1.0</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">encoding</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">iso-8859-1</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">standalone</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">yes</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">?></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">catalog</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><![CDATA[</span><span style=""color:Gray;"">An in-depth look at creating applications with XML, using <, >,</span><span style=""color:Blue;"">]]></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">catalog</span><span style=""color:Blue;"">></span>;
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleXmlMultilineCDATA()
|
||||
{
|
||||
string source =
|
||||
@"<?xml version=""1.0"" encoding=""iso-8859-1"" standalone=""yes""?>
|
||||
<catalog>
|
||||
<![CDATA[An in-depth look at creating
|
||||
applications with XML, using <, >,]]>
|
||||
</catalog>";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><?</span><span style=""color:#A31515;"">xml</span> <span style=""color:Red;"">version</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">1.0</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">encoding</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">iso-8859-1</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">standalone</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">yes</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">?></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">catalog</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><![CDATA[</span><span style=""color:Gray;"">An in-depth look at creating
|
||||
applications with XML, using <, >,</span><span style=""color:Blue;"">]]></span>
|
||||
<span style=""color:Blue;""></</span><span style=""color:#A31515;"">catalog</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleXmlDoctype()
|
||||
{
|
||||
string source =
|
||||
@"<?xml version=""1.0"" encoding=""iso-8859-1"" standalone=""yes""?>
|
||||
<!DOCTYPE catalog SYSTEM ""Test.dtd"">
|
||||
<catalog />";
|
||||
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><?</span><span style=""color:#A31515;"">xml</span> <span style=""color:Red;"">version</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">1.0</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">encoding</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">iso-8859-1</span><span style=""color:Black;"">"</span> <span style=""color:Red;"">standalone</span><span style=""color:Blue;"">=</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">yes</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">?></span>
|
||||
<span style=""color:Blue;""><!</span><span style=""color:#A31515;"">DOCTYPE</span> <span style=""color:Red;"">catalog</span> <span style=""color:Red;"">SYSTEM</span> <span style=""color:Black;"">"</span><span style=""color:Blue;"">Test.dtd</span><span style=""color:Black;"">"</span><span style=""color:Blue;"">></span>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">catalog</span> <span style=""color:Blue;"">/></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnElementNameThatContainsUnderscore()
|
||||
{
|
||||
string source =
|
||||
@"<e_s>someText</e_s>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">e_s</span><span style=""color:Blue;"">></span>someText<span style=""color:Blue;""></</span><span style=""color:#A31515;"">e_s</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillStyleAnElementNameThatContainsDash()
|
||||
{
|
||||
string source =
|
||||
@"<e-s>someText</e-s>";
|
||||
string expected =
|
||||
@"<div style=""color:Black;background-color:White;""><pre>
|
||||
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">e-s</span><span style=""color:Blue;"">></span>someText<span style=""color:Blue;""></</span><span style=""color:#A31515;"">e-s</span><span style=""color:Blue;"">></span>
|
||||
</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransformWillCommentMultipleCommentsCorrectly()
|
||||
{
|
||||
string source = "<!-- test --><root><elment><!-- comment inside of element --></element></root>";
|
||||
string expected =
|
||||
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Green;\"><!-- test --></span><span style=\"color:Blue;\"><</span><span style=\"color:#A31515;\">root</span><span style=\"color:Blue;\">></span><span style=\"color:Blue;\"><</span><span style=\"color:#A31515;\">elment</span><span style=\"color:Blue;\">></span><span style=\"color:Green;\"><!-- comment inside of element --></span><span style=\"color:Blue;\"></</span><span style=\"color:#A31515;\">element</span><span style=\"color:Blue;\">></span><span style=\"color:Blue;\"></</span><span style=\"color:#A31515;\">root</span><span style=\"color:Blue;\">></span>\r\n</pre></div>";
|
||||
|
||||
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1 +0,0 @@
|
|||
ADA|ADD|AFTER|ALL|ALTER|AND|ANY|AS|ASC|AT|AUTHORIZATION|AVG|BACKUP|BEGIN|BETWEEN|BINARY|BIT|BIT_LENGTH|BOOLEAN|BREAK|BROWSE|BULK|BY|CASCADE|CASE|CAST|CATALOG|CHAR|CHARACTER|CHARACTER_LENGTH|CHAR_LENGTH|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMN|COMMIT|COMPUTE|CONNECT|CONNECTION|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|COUNT|CREATE|CROSS|CUBE|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATABASE|DATE|DATETIME|DAY|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFERRED|DELETE|DENY|DESC|DISK|DISTINCT|DISTRIBUTED|DOUBLE|DROP|DUMMY|DUMP|ELSE|END-EXEC|END|ERRLVL|ESCAPE|EXCEPT|EXEC|EXECUTE|EXISTS|EXIT|EXTERNAL|EXTRACT|FALSE|FETCH|FILE|FILLFACTOR|FIRST|FLOAT|FOR|FOREIGN|FORTRAN|FREE|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GLOBAL|GOTO|GRANT|GROUP|GROUPING|HAVING|HOLDLOCK|HOUR|IDENTITY|IDENTITYCOL|IDENTITY_INSERT|IF|IGNORE|IMAGE|IMMEDIATE|IN|INCLUDE|INDEX|INNER|INSENSITIVE|INSERT|INT|INTEGER|INTERSECT|INTO|IS|ISOLATION|JOIN|KEY|KILL|LANGUAGE|LAST|LEFT|LEVEL|LIKE|LIMIT|LINENO|LOAD|LOCAL|LOWER|MAX|MIN|MINUTE|MODIFY|MONTH|NAME|NATIONAL|NCHAR|NEXT|NO|NOCHECK|NONE|NOT|NULL|NULLIF|NUMERIC|OCTET_LENGTH|OF|OFF|OFFSETS|ON|ONLY|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPENXML|OPTION|OR|ORDER|OUTER|OUTPUT|OVER|OVERLAPS|PARTIAL|PASCAL|PERCENT|PLAN|POSITION|PRECISION|PREPARE|PRIMARY|PRINT|PRIOR|PRIVILEGES|PROC|PROCEDURE|PUBLIC|RAISERROR|READ|READTEXT|REAL|RECONFIGURE|REF|REFERENCES|REPLICATION|RESTORE|RESTRICT|RETURN|RETURNS|REVOKE|RIGHT|ROLLBACK|ROLLUP|ROWCOUNT|ROWGUIDCOL|ROWS|RULE|SAVE|SCHEMA|SCROLL|SECOND|SECTION|SELECT|SEQUENCE|SESSION|SESSION_USER|SET|SETUSER|SHUTDOWN|SIZE|SMALLINT|SOME|SPACE|SQLCA|SQLERROR|STATISTICS|SUBSTRING|SUM|SYSTEM_USER|TABLE|TEMPORARY|TEXT|TEXTSIZE|THEN|TIME|TIMESTAMP|TIMEZONE_HOUR|TO|TOP|TRAN|TRANSACTION|TRANSLATION|TRIGGER|TRUE|TRUNCATE|TSEQUAL|UNION|UNIQUE|UNNEST|UPDATE|UPDATETEXT|UPPER|USE|USER|VALUE|VALUES|VARCHAR|VARYING|VIEW|WAITFOR|WHEN|WHERE|WHILE|WITH|WORK|WRITETEXT|YEAR
|
|
@ -1,36 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ColorCodeAcceptanceTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ColorCodeAcceptanceTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2008")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d393e499-78ad-4f21-8e68-e80bc1990318")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -1,194 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ColorCode.Parsing;
|
||||
using ColorCode.Stubs;
|
||||
using Xunit;
|
||||
|
||||
namespace ColorCode
|
||||
{
|
||||
public class CodeColorizerFacts
|
||||
{
|
||||
public class The_constructor
|
||||
{
|
||||
[Fact]
|
||||
public void Will_throw_if_the_language_parser_is_null()
|
||||
{
|
||||
// no arrange
|
||||
|
||||
Exception ex = Record.Exception(() => new CodeColorizer(null));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("languageParser", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
}
|
||||
|
||||
public class The_Colorize_method
|
||||
{
|
||||
[Fact]
|
||||
public void Will_write_the_header()
|
||||
{
|
||||
StubLanguageParser stubLanguageParser = new StubLanguageParser();
|
||||
CodeColorizer codeColorizer = new CodeColorizer(stubLanguageParser);
|
||||
const string sourceCode = "fnord";
|
||||
StubFormatter stubFormatter = new StubFormatter();
|
||||
StubStyleSheet stubStyleSheet = new StubStyleSheet();
|
||||
StubTextWriter stubTextWriter = new StubTextWriter();
|
||||
|
||||
codeColorizer.Colorize(sourceCode, new StubLanguage(), stubFormatter, stubStyleSheet, stubTextWriter);
|
||||
|
||||
Assert.Equal(stubTextWriter, stubFormatter.WriteHeader__textWriter);
|
||||
Assert.Equal(stubStyleSheet, stubFormatter.WriteHeader__styleSheet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_parse_the_source_code()
|
||||
{
|
||||
StubLanguageParser stubLanguageParser = new StubLanguageParser();
|
||||
CodeColorizer codeColorizer = new CodeColorizer(stubLanguageParser);
|
||||
const string sourceCode = "fnord";
|
||||
StubLanguage stubLanguage = new StubLanguage();
|
||||
|
||||
codeColorizer.Colorize(sourceCode, stubLanguage, new StubFormatter(), new StubStyleSheet(), new StubTextWriter());
|
||||
|
||||
Assert.Equal(sourceCode, stubLanguageParser.Parse__sourceCode);
|
||||
Assert.Equal(stubLanguage, stubLanguageParser.Parse__language);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_write_the_parsed_source_code()
|
||||
{
|
||||
StubLanguageParser languageParser = new StubLanguageParser();
|
||||
languageParser.Parse__do = (sourceCodeToParse, language, parsedSourceCodeHandler) =>
|
||||
{
|
||||
parsedSourceCodeHandler("parsedSourceCode1", new List<Scope>());
|
||||
parsedSourceCodeHandler("parsedSourceCode2", new List<Scope>());
|
||||
};
|
||||
CodeColorizer codeColorizer = new CodeColorizer(languageParser);
|
||||
const string sourceCode = "fnord";
|
||||
StubFormatter formatter = new StubFormatter();
|
||||
|
||||
codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, new StubStyleSheet(), new StubTextWriter());
|
||||
|
||||
Assert.Equal("parsedSourceCode2", formatter.Write__parsedSourceCode.Pop());
|
||||
Assert.Equal("parsedSourceCode1", formatter.Write__parsedSourceCode.Pop());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_write_the_parsed_source_code_using_the_defaults()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer();
|
||||
const string sourceCode = "fnord";
|
||||
StubTextWriter textWriter = new StubTextWriter();
|
||||
|
||||
codeColorizer.Colorize(sourceCode, Languages.Html, textWriter);
|
||||
|
||||
Assert.Contains("fnord", textWriter.Write__buffer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_write_the_parsed_source_code_using_the_defaults_without_the_textwriter()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer();
|
||||
const string sourceCode = "fnord";
|
||||
StubTextWriter textWriter = new StubTextWriter();
|
||||
|
||||
string output = codeColorizer.Colorize(sourceCode, Languages.Html);
|
||||
|
||||
Assert.Contains("fnord", output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_write_the_footer()
|
||||
{
|
||||
StubLanguageParser languageParser = new StubLanguageParser();
|
||||
CodeColorizer codeColorizer = new CodeColorizer(languageParser);
|
||||
const string sourceCode = "fnord";
|
||||
StubFormatter formatter = new StubFormatter();
|
||||
StubStyleSheet styleSheet = new StubStyleSheet();
|
||||
StubTextWriter writer = new StubTextWriter();
|
||||
|
||||
codeColorizer.Colorize(sourceCode, new StubLanguage(), formatter, styleSheet, writer);
|
||||
|
||||
Assert.Equal(writer, formatter.WriteFooter__writer);
|
||||
Assert.Equal(styleSheet, formatter.WriteFooter__styleSheet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_language_is_null()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer(new StubLanguageParser());
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, null, new StubFormatter(), new StubStyleSheet(), new StubTextWriter()));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("language", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_language_is_null_using_defaults()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer();
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, null, new StubTextWriter()));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("language", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_language_is_null_using_defaults_without_text_writer()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer();
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, null));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("language", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_formatter_is_null()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer(new StubLanguageParser());
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, new StubLanguage(), null, new StubStyleSheet(), new StubTextWriter()));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("formatter", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_style_sheet_is_null()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer(new StubLanguageParser());
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, new StubLanguage(), new StubFormatter(), null, new StubTextWriter()));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("styleSheet", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_text_writer_is_null()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer(new StubLanguageParser());
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, new StubLanguage(), new StubFormatter(), new StubStyleSheet(), null));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("textWriter", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Will_throw_if_the_text_writer_is_null_using_defaults()
|
||||
{
|
||||
CodeColorizer codeColorizer = new CodeColorizer();
|
||||
|
||||
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, new StubLanguage(), null));
|
||||
|
||||
Assert.IsType<ArgumentNullException>(ex);
|
||||
Assert.Equal("textWriter", ((ArgumentNullException)ex).ParamName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче